Skip to content

Instantly share code, notes, and snippets.

@henrybear327
Created October 14, 2017 08:07
Show Gist options
  • Save henrybear327/0e106e189ce700ebb56825b99cecd105 to your computer and use it in GitHub Desktop.
Save henrybear327/0e106e189ce700ebb56825b99cecd105 to your computer and use it in GitHub Desktop.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll P = 65537;
ll x[3];
ll y[3];
ll cal(ll a0, ll a1, ll a2, int which)
{
ll x_2 = x[which] * x[which] % P;
return (((a0 + a1 * x[which]) % P + a2 * x_2) % P);
}
void solve()
{
for(int i = 0; i < 3; i++)
scanf("%lld %lld", &x[i], &y[i]);
ll x_2 = (x[0] * x[0]) % P;
for(ll a1 = 0; a1 < P; a1++) {
for(ll a2 = 0; a2 < P; a2++) {
ll a0 = 5 * P + y[0] - (a1 * x[0]) % P - (a2 * x_2) % P;
a0 %= P;
assert(cal(a0, a1, a2, 0) == y[0]);
if(cal(a0, a1, a2, 1) == y[1] && cal(a0, a1, a2, 2) == y[2]) {
printf("%lld %lld %lld\n", a0, a1, a2);
return;
}
}
}
}
int main()
{
int ncase;
scanf("%d", &ncase);
while(ncase--)
solve();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment