Time Limit: 6000MS | | Memory Limit: 65536K |
Total Submissions: 29046 | | Accepted: 7342 |
Case Time Limit: 4000MS |
Description
Given a big integer number, you are required to find out whether it's a prime number.
Input
The first line contains the number of test cases T (1 <= T <= 20 ), then the following T lines each contains an integer number N (2 <= N < 2
54).
Output
For each test case, if N is a prime number, output a line containing the word "Prime", otherwise, output a line containing the smallest prime factor of N.
Sample Input
2510
Sample Output
Prime2
Source
Mean:
略。
analyse:
输入的n很大,我们不可能再用筛法来求素数,这时Miller_Rabin算法就显得尤为重要。
若n不是素数,需要进行质因数分解,同样的问题,n很大,我们不可能用试除法来进行质因数分解,那样必会tle。这时就必须使用pollard_rho算法来进行质因数分解。
其实Miller_Rabin算法和pollard_rho算法很多时候是组合在一起用的。
Time complexity:O(n) 一般情况下是O(n)
Source code:
//Memory Time// 1347K 0MS// by : Snarl_jsb#include #include #include #include #include #include #include #include #include