以下是引用风影空在2010-10-8 12:33:49的发言:
import java.util.*;
public class main{
public static void main(String args[]){
Scanner reader=new Scanner(System.in);
System.out.println("Please input g,x,p(Separated By Space):");
System.out.print("g=");
long g=reader.nextLong();
System.out.print("x=");
long x=reader.nextLong();
System.out.print("p=");
long p=reader.nextLong();
System.out.println("y:"+Math.pow(g, x) % p);
}
这是我原来的程序 应该如何改呢???
import java.math.*;
import java.util.*;
public class main{
public static void main(String args[]){
BigDecimal t[],s;
Scanner reader=new Scanner(System.in);
System.out.println("Please input g,x,p(Separated By Space):");
System.out.print("g=");
BigDecimal g=new BigDecimal(reader.nextLong());
System.out.print("x=");
int x=reader.nextInt();
System.out.print("p=");
BigDecimal p=new BigDecimal(reader.nextLong());
s = g.pow(x);
t = s.divideAndRemainder(p);
System.out.println("y:"+t[1]);
}
}