Number of factors for CPP 1192 integers

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.