欧拉判定准则 Java
根据欧拉判定准则,当且仅当存在一个数字 _num_ 使得 num%p 等于 n%p,则 n 在模 p 下开平方根。
程序
import java.util.Scanner; public class EulersCriterion { public static void main(String args[]) { Scanner sc = new Scanner(System.in); System.out.println("Enter n value :"); int n = sc.nextInt(); System.out.println("Enter p value :"); int p = sc.nextInt(); n = n % p; int flag = 0; for (int num = 2; num < p; num++) { if ((num * num) % p == n) { flag = 1; } } if(flag==1) { System.out.println("root of a number under modulo p exists "); } else { System.out.println("root of a number under modulo p does not exists "); } } }
输出
Enter n value : 2 Enter p value : 7 root of a number under modulo p exists
广告