Title Link: http://cpp.zjut.edu.cn/ShowProblem.aspx?ShowID=1192
Surface:
number of factors for integers
Time limit:2000ms Memory limit:32768k
Description: Finds all the number of factors in an integer. The number of factors for an integer n is the number of all factors that contain it itself. For example: 12 The number of factors is 6 (1,2,3,4,6,12).
Input: Some integer n (1≤n<2^32) is included in the data. Output: For each n, list all of its factors, each n plus a colon, one row at a separate column. Sample Input:
11 22 33 24
Sample Output:
11:222:433:424:8
Source:qianneng
Test instructions
In particular, the amount of data is too large. I'm kind of water, there's no big prime number in the data. Divide each number into prime numbers, and then count the number of each of its prime numbers. The number of factors is the result of +1 multiplication for each prime number. The proof is very simple, each prime number can take 0 to its several, so prove.
Today, a great God said it was with Pollard Rho, looked under the feeling still very good can not solve a large number of prime, but there is still time to try.
There should be a better way to find a supplement.
Code:
#include <iostream> #include <map> #include <cmath>using namespace std ; map <unsigned int,int> store;bool is_prime (unsigned int x) {if (x==1) return False;else if (x==2) return True;int y= sqrt (1.0*x); for (int i=2;i<=y;i++) {if (x%i==0) return false;} return true;} void cal (unsigned int x) {if (Is_prime (x)) Store[x]++;else{int y=sqrt (1.0*x); for (int i=2;i<=y;i++) {if (x%i==0) {cal (I ); Cal (x/i); break;}}}} int main () {unsigned int n,tmp,ans;while (cin>>n) {cout<<n<< ":"; ans=1;if (n==1) {cout<<1< <endl;continue;} Store.clear (); int up_limit=sqrt (1.0*N); Tmp=n; for (int i=2;i<=up_limit;i++) {if (tmp%i==0) {cal (i); Cal (tmp/i); }} if (Store.size () ==0) {cout<<2<<endl; Continue } map <unsigned int,int>:: Iterator iter; For (Iter=store.begin (); Iter!=store.end (); iter++) ans*= ((Iter->second) +1); Cout<<ans<<endl;} return 0;}
Number of factors for CPP 1192 integers