QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#267182 | #5103. Fair Division | juampi | Compile Error | / | / | Python3 | 1.8kb | 2023-11-27 00:58:46 | 2023-11-27 00:58:47 |
Judging History
answer
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String[] tokens = in.nextLine().split(" ");
int n = Integer.parseInt(tokens[0]);
int m = Integer.parseInt(tokens[1]);
int p = -1;
int q = -1;
for (int qTest = 2; qTest <= 6000; qTest++) {
int term = (int) Math.pow(qTest, n - 1);
if (m < term) {
break;
}
term *= qTest;
boolean found = false;
for (int pTest = qTest - 1; pTest >= 0; pTest--) {
if (gcd(qTest, pTest) != 1) {
continue;
}
int sub = (int) Math.pow(pTest, n);
int div = term - sub;
int top = m * (qTest - pTest);
if (div > top) {
continue;
}
found = true;
if (top % div == 0) {
p = pTest;
q = qTest;
break;
}
}
if (found) {
break;
}
}
if (p == -1) {
System.out.println("impossible");
} else {
System.out.println(p + " " + q);
}
}
public static int gcd(int a, int b) {
if (b == 0) {
return a;
}
return gcd(b, a % b);
}
public static long mypow(long b, int e) {
long res = 1;
long term = b;
while (e > 0) {
if ((e & 1) == 1) {
res = res * term;
}
e >>= 1;
term *= term;
}
return res;
}
}
Details
File "answer.code", line 3 public class Main { ^^^^^ SyntaxError: invalid syntax