ENG  RUS Timus Online Judge
Online Judge
Problems
Authors
Online contests
Site news
Webboard
Problem set
Submit solution
Judge status
Guide
Register
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

## Discussion of Problem 1110. Power

Pascal - AC, but Java - WA
Posted by Maxim_tmn 10 Apr 2014 17:17
In Pascal I have AC, but in Java - WA, why??

/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Ideone
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner in = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);

int N, M, Y = 0;
boolean check = false;

N = in.nextShort();
M = in.nextShort();
Y = in.nextShort();

double p;

if ( ((0<N) && (N<999)) && ((1<M) && (M<999)) && ((0<Y) && (Y<999)) ) {
for (int X=0; X<=M-1; ++X) {
p = ((Math.pow(X,N)) % M);
if (p == Y) {
if (X != (M-2)) {
out.print(X + " ");
} else {
out.print(X);
}
check = true;
}
}
}

if (!check) {
out.print("-1");
}

out.flush();
}
}