<del></del>
/*1/x+1/y=1/n
give you an integer n to find the number of x, y combinations (n<=10^9)
x, y two variables in the formula can be converted into one condition
Suppose y=n+m; the expression of x is x=n*n/m+n;
The condition is if (n*n%m==0)
So the answer is the number of n*n factors.
Obviously, the general method will be timed out directly.
But the factor of n is seldom the maximum is sqrt (n);
Each number can represent the product of the element factor
N= (Prime[0]^ans[0]) * ((prime[1]^ans[1]) * ....
Knowing the number of each factor, the other non-element factors of n can be combined by the element factor.
So sum= (1+ans[0]) * (1+ans[1]) ...//, this kind of combination of the mother function,1 means no, we just need his coefficient
Because N*n= ((prime[0]^ (ans[0]*2)) * ((prime[1]^ (ans[1]*2)) * ....
sum= (1+ans[0]*2) * (1+ans[1]*2) ... * *
must transform the formula into a condition to find an unknown expression.
Suppose y=n+m; the expression of x is x=n*n/m+n;
So the answer is the number of n*n factors.
Obviously, it's going to time out.
But the n factor is rarely sqrt (n);
Each number can represent the product of the element factor
N= (Prime[0]^ans[0]) * ((prime[1]^ans[1]) * ....
I know the number of each element factor.
1 means no so sum= (1+ans[0]) * (1+ans[1]) ...
Because N*n= ((prime[0]^ (ans[0]*2)) * ((prime[1]^ (ans[1]*2)) * ....
sum= (1+ans[0]*2) * (1+ans[1]*2) ... * *
#include <stdio.h> #include <string.h> #define LL __int64#define N 330000//The largest element factor is sqrt (n) bool Used[n];int Prime[n];int cnt;void init () { memset (used,false,sizeof (used)); for (int i=2;i<n;i++) { if (!used[i]) { prime[cnt++]=i;//filter element factor for (int j=i;j<n;j+=i) { used[j]=true;}}} } int main () { int t,k=1; cnt=0; Init (); scanf ("%d", &t); while (t--) { ll n,sum=1; scanf ("%i64d", &n); for (int i=0;i<cnt;i++) { ll ans=0; if (prime[i]>n) break ; while (n%prime[i]==0) { ans++; N/=prime[i]; } Sum= (2*ans+1) *sum; } if (n>1)//n itself is a prime word sum*=3; printf ("Scenario #%d:\n", k++); printf ("%i64d\n\n", sum/2+1); } return 0;}
HDU 1299 Diophantus of Alexandria