Skip to content

Instantly share code, notes, and snippets.

@id-ilych
Created April 7, 2019 17:36
Show Gist options
  • Save id-ilych/88174c88100e0f0ac3e7d8ae15ef7e61 to your computer and use it in GitHub Desktop.
Save id-ilych/88174c88100e0f0ac3e7d8ae15ef7e61 to your computer and use it in GitHub Desktop.
Contest dumb fail I've made :(
// what I carelessly wrote
BigInteger value = ciphertext[0];
BigInteger p, o;
if (value.equals(ciphertext[1])) { // << here's careless fail. Never should've done it
BigInteger[] factors = factorize(value);
p = factors[0];
o = factors[1];
} else {
p = gcd(value, ciphertext[1]);
o = value.divide(p);
}
if (p.equals(o)) {
push.accept(p);
push.accept(o);
} else {
for (int i = 1; i < L; ++i) {
BigInteger x = ciphertext[i];
if (x.equals(value)) {
continue;
}
boolean test = x.remainder(p).signum() != 0;
if (i % 2 == 0) {
test = !test;
}
if (test) {
push.accept(p);
push.accept(o);
} else {
push.accept(o);
push.accept(p);
}
break;
}
}
// what should I wrote insted to pass (call to `factorize` takes too much time on big numbers)
BigInteger value = ciphertext[0];
int i = 1;
while (value.equals(ciphertext[i])) {
++i;
}
BigInteger p = gcd(value, ciphertext[i]);
BigInteger o = value.divide(p);
if (i % 2 == 0) {
push.accept(p);
push.accept(o);
} else {
push.accept(o);
push.accept(p);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment