https://ac.nowcoder.com/acm/contest/3346/K
The meaning of problems: determining a prime number p not a difference between the two cubic numbers.
This question is just to see half past one would have no idea, read the solution to a problem suddenly realized, too long did not touch math or number theory, about the recording process.
1. The difference between the cubic equation: X . 3 - Y . 3 = (XY) (X 2 + Y XY + 2 )
2.(x-y)(x2 + xy + y2)=p
3. Because p is a prime number, so that xy = 1
4. x = y + 1 obtained simply formulated into the original 3y (y + 1) = p-1
5. To set up the above formula, (p-1)% 3 == 0 && sqrt ((p-1) / 3) * (sqrt ((p-1) / 3) +1) == (p-1 ) / 3
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan=new Scanner(System.in); int n; n=scan.nextInt(); long p; while(n!=0) { n--; p=scan.nextLong(); if((p-1)%3==0) { P = (. 1-P) /. 3 ; Long Y = ( Long ) the Math.sqrt (P); // rounded down IF (Y * (Y +. 1) == P) System.out.println("YES"); else System.out.println("NO"); }else System.out.println("NO"); } } }