Java中的Euler准则
根据欧拉准则,当且仅当存在数字num 使得num%p等于n%p时,模p下的n的平方根才存在。
程序
import java.util.Scanner;
public class EulersCriterion {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.println("输入n值:");
int n = sc.nextInt();
System.out.println("输入p值:");
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("模p下的数字的根存在 ");
} else {
System.out.println("模p下的数字的根不存在 ");
}
}
}输出结果
输入n值: 2 输入p值: 7 模p下的数字的根存在
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短