Skip to content

Instantly share code, notes, and snippets.

@kunishi
Created October 8, 2015 02:31
Show Gist options
  • Save kunishi/2c852c28db024331b10a to your computer and use it in GitHub Desktop.
Save kunishi/2c852c28db024331b10a to your computer and use it in GitHub Desktop.
/* @JUDGE_ID: 26089N 113 Java "" */
import java.io.*;
import java.math.*;
import java.util.*;
class Main {
static String readLn(int max) {
byte lin[] = new byte[max];
int l = 0;
int car = -1;
String line = "";
try {
while (l < max) {
car = System.in.read();
if ((car < 0) || (car == '\n'))
break;
lin[l ++] += car;
}
} catch (IOException e) {
return null;
}
if ((car < 0) && (l == 0))
return null;
return (new String(lin, 0, l));
}
public static void main(String args[]) {
Main mywork = new Main();
mywork.begin();
}
void begin() {
String input;
int n;
BigInteger p, pp;
while ((input = Main.readLn(255)) != null) {
n = Integer.parseInt(input);
input = Main.readLn(255);
p = new BigInteger(input);
pp = p.subtract(BigInteger.ONE);
BigInteger i = new BigInteger("2");
loop:
do {
if (pp.mod(i).equals(BigInteger.ZERO)) {
BigInteger ii = i.add(BigInteger.ONE);
switch (ii.pow(n).compareTo(p)) {
case 0:
System.out.println(ii);
break loop;
case 1:
break loop;
}
}
i = i.add(BigInteger.ONE);
} while (true);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment