|
|
вернуться в форумTime Limit Exceed #8 (Java) import java.math.BigInteger; import java.util.Scanner; public class Main { public static BigInteger step(int a, int b) { BigInteger temp=BigInteger.valueOf(a); for (int i=1; i<b; i++) { temp=temp.multiply(BigInteger.valueOf(a)); } return temp; } public static void main(String[] args) { Scanner inp=new Scanner(System.in); int n=inp.nextInt(); int m=inp.nextInt(); int y=inp.nextInt(); boolean f=false; for (int i=0;i<m;i++) { BigInteger x=step(i,n); BigInteger c=x.mod(BigInteger.valueOf(m)); if (c.compareTo(BigInteger.valueOf(y))==0) { System.out.print(i+" "); f=true; } } if (f==false) System.out.print("-1"); } } I don't know how to do it faster, than now. Please help me. Edited by author 03.02.2013 15:10 Re: Time Limit Exceed #8 (Java) you don't need to use BigInteger =) |
|
|