Unique Factorization Theorem : a positive integer greater than 1 for each of the product can be decomposed into a finite number of prime numbers, if prime factor excluding the product in order, the decompositions are unique. The prime factorization of n same prime factor collected together, may only be a positive integer n greater than 1 each may be uniquely written as P = n 1 A1 P 2 A2 P . 3 A3 ... P K AK ,wherein, p1,P2, P . 3, ..., PK , are mutually different prime numbers, and a1, a2, a3, ..., ak is a positive integer, above referred to as n-type decomposition of the canonical decomposition.
Properties: The number n of the divisor n, τ (n) = (1 + a1) (1 + a2) (1 + a3) ...... (1 + ak); n is the number of positive and about, [sigma] (n-) = (. 1 P1 + P1 + ... + A1 ) (. 1 P2 + P2 + ... + A2 ) ... (. 1 + PK + ... + PK AK )
Template code:
1 /* */ 2 #include <iostream> 3 #include <cstdio> 4 #include <cstring> 5 #include <string> 6 #include <cmath> 7 #include <algorithm> 8 using namespace std; 9 typedef long long ll; 10 const int maxn=1e5; 11 bool is[maxn]; 12 int cnt=0; 13 ll a[maxn];//存素数 14DS LL [MAXN], ZS [MAXN]; // DS is the base, ZS is the index 15 16 void the init () // play table, Euler sieve . 17 { 18 is Memset ( IS , to true , the sizeof ( IS )); . 19 IS [ 0 ] = IS [ . 1 ] = to false ; 20 is for ( int I = 2 ; I <MAXN; I ++ ) 21 is { 22 is IF ( IS [I]) A [CNT ++] = I; 23 is for (int j=0; i*a[j]<maxn&&j<cnt; j++) 24 { 25 is[i*a[j]]=false; 26 if( i%a[j]==0 ) break; 27 } 28 } 29 } 30 31 ll fj(ll x)//不同素数的个数 32 { 33 ll k=0,flag=0; 34 for(ll i=0; i<cnt; i++ ) 35 { 36 while(x%a[i]==0) 37 { 38 if(flag==0) 39 { 40 flag=1; 41 k++; 42 } 43 x/=a[i]; 44 ds[k]=a[i]; 45 zs[k]++; 46 } 47 if(x==1) break; 48 flag=0; 49 } 50 if(! X = 1 ) // If exploded End x are not equal to 1, then x must be a prime number 51 is { 52 is K ++ ; 53 is DS [K] = x; 54 is ZS [K] = 1 ; 55 } 56 is return K; 57 is } 58 59 int main () 60 { 61 is the init (); 62 is LL X; 63 is CIN >> X; 64 LL K = FJ (X); 65 for (LL I = . 1 ; I <= K; I ++) the printf ( " % c% LLD LLD ^%",ds[i],zs[i],i==k?'\n':'+'); 66 return 0; 67 }