2013
12-04

# Diophantus of Alexandria

Diophantus of Alexandria was an egypt mathematician living in Alexandria. He was one of the first mathematicians to study equations where variables were restricted to integral values. In honor of him, these equations are commonly called diophantine equations. One of the most famous diophantine equation is x^n + y^n = z^n. Fermat suggested that for n > 2, there are no solutions with positive integral values for x, y and z. A proof of this theorem (called Fermat’s last theorem) was found only recently by Andrew Wiles.

Consider the following diophantine equation:

1 / x + 1 / y = 1 / n where x, y, n ∈ N+ (1)

Diophantus is interested in the following question: for a given n, how many distinct solutions (i. e., solutions satisfying x ≤ y) does equation (1) have? For example, for n = 4, there are exactly three distinct solutions:

1 / 5 + 1 / 20 = 1 / 4
1 / 6 + 1 / 12 = 1 / 4
1 / 8 + 1 / 8 = 1 / 4

Clearly, enumerating these solutions can become tedious for bigger values of n. Can you help Diophantus compute the number of distinct solutions for big values of n quickly?

The first line contains the number of scenarios. Each scenario consists of one line containing a single number n (1 ≤ n ≤ 10^9).

The output for every scenario begins with a line containing "Scenario #i:", where i is the number of the scenario starting at 1. Next, print a single line with the number of distinct solutions of equation (1) for the given value of n. Terminate each scenario with a blank line.

2
4
1260

Scenario #1:
3

Scenario #2:
113

题目大意：给你一个数Ｎ　求　１／Ｘ＋１／Ｙ＝１／Ｎ　中Ｘ　，Ｙ　有几种组合。

分析思路：　由题意可知　Ｘ〉Ｎ，Ｙ〉N。  我们可令 Y=N+ K（K为正整数）。

化简可得 X= （N* N）/ K + N 。   X，Y 为正整数 。

所以呢， 只需N* N的因子数即可。

知道了这个，之后就直接 A 就行。

代码如下：

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

#define Len 50000

bool a[Len];
int b[Len];
int k;
void Isprime()
{
int i,j;
a[2]=true;
k=1;
b[0]=2;
for(i=3;i<Len;i++)
{
if(i&1)
a[i]=true;
else
false;
}
for(i=3;i<Len;i++)
{
if(a[i])
{
b[k]=i;
k++;
for(j=i+i;j<Len;j+=i)
a[j]=false;
}
}
}
int main()
{
Isprime();
int x,n,i,j,sum,m=1,t;
scanf("%d",&n);
while(n--)
{
j=0;
sum=1;
scanf("%d",&x);
for(i=0;i<k;i++)
{
t=0;
if(x<b[i])
break;
while(x%b[i]==0 )
{
x=x/b[i];
t++;
}
sum *= (t*2+1);
j++;
}
printf("Scenario #%d:\n",m);
m++;
if(x>1)  // 可能 存在 一个 素数 X .
sum*=3;
printf("%d\n\n",(sum+1)/2);
}
return 0;
}

1. 恩，高帅富都忙着败家去了……话说我对短发的女生挺有好感的，觉得此类型的妹子够直率。好奇，图里的那水生植物是啥。。。。