首页 > 代码库 > 刷题_牛客_超级素数幂

刷题_牛客_超级素数幂

技术分享

 1 import java.util.Scanner;
 2 
 3 public class Main {
 4     public static boolean isPrime(long m) {
 5         if (m <= 1)
 6             return false;
 7         for (int i = 2; i * i < m; i++) {
 8             if (m % i == 0)
 9                 return false;
10         }
11         return true;
12     }
13 
14     public static void main(String[] args) {
15         Scanner in = new Scanner(System.in);
16         long n = in.nextLong();
17         double p;
18         boolean flag = false;
19         for (int q = 2; q * q < n; q++) {
20             p = Math.pow((double) n, (double) 1 / q);
21             if((long)p == p && isPrime((long)p)){
22                 System.out.println(p + " " + "q");
23                 flag = true;
24                 return;
25             }  
26         }
27         if(!flag){
28             System.out.println("No");
29         }
30         
31     }
32 
33 }

 

刷题_牛客_超级素数幂