LOJ10202 cherry - Number Theory

Title Description

From the original title: HackerRank the Equations

Indefinite equation:

 1 / x + 1 / y = 1 / n!

Positive integer solution (x, y)  number.

Input Format

An integer  the n- .

Output Format

An integer representing the number of (x, y)  satisfy the meaning of the questions. The answer to 1e9 + 7  mod.

Sample

Sample input

2

Sample Output

3

Sample Description

There are three pairs of (x, y)  satisfies the condition, respectively (3,6), (4,4)  and (6,3) .

Data range and tips

For 30%  of the data, n-<= 100 ;
for all data, n-<= 1e6 .

___________________________________________________________________

Number of topics, a key step in really unexpected!

Since the subject is a positive integer solution, the x, y are greater than n

Title easily into n! = Xy / (x + y)

Since x, y is greater than n !. So x set n! + A, y is set to n! + B.

The above equation can be turned into (n!) ^ 2 = a * b

That is, the above formula, a, b how much there is in the solution!

So, first of all find a prime number n, and then find all the primes in n! Times appear, while (n!) ^ Number of prime numbers after 2 multiplied by 2, so that is the desire of all factors number.

___________________________________________________________________

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 const int maxn=1e6;
 4 int n;
 5 int prime[maxn],cnt[maxn];
 6 bool sz[maxn];
 7 int js;
 8 void getprime(int n)
 9 {
10     sz[0]=sz[1]=1;
11     for(int i=2;i<=n;++i)
12     {
13         if(sz[i]==0)prime[js++]=i;
14         for(int j=0;j<js&&prime[j]*i<=n;++j)
15         {
16             sz[prime[j]*i]=1;
17             if(i%prime[j]==0)break;
18         }
19     }
20 }
21 void fenjie(int x)
22 {
23     for(int i=0;prime[i]*prime[i]<=x;++i)
24         while(x%prime[i]==0)
25         {
26             x/=prime[i];
27             cnt[prime[i]]++;
28         }
29     if(x!=1)cnt[x]++;
30 }
31 long long ans=1;
32 int main()
33 {
34     cin>>n;
35     getprime(n);
36     for(int i=2;i<=n;++i)fenjie(i);
37     for(int i=2;i<=n;++i)ans=(ans*((cnt[i]<<1)+1))%1000000007;
38     cout<<ans;
39     return 0;
40 }
View Code

 

Guess you like

Origin www.cnblogs.com/gryzy/p/11496229.html