Diophantus of Alexandria
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 2081 Accepted Submission(s): 788
Problem Description
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?
Consider the following diophantine equation:
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 / 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?
Input
The first line contains the number of scenarios. Each scenario consists of one line containing a single number n (1 ≤ n ≤ 10^9).
Output
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.
Sample Input
2 4 1260
Sample Output
Scenario #1: 3 Scenario #2: 113
Source
Recommend
JGShining
这个题目我觉得真心是不简单,但是在我看了很多大神的结题报告之后,终于明白了究竟这个题目应该怎么
去做
的,应该说是非常不好办的。(我今天晚上本来心怀希望的,不过事实还是沉痛的打击了我,我要等的那还
是没有等到,唉,为什么我的感情就不能像ACM一样通过不断的思索与努力就必然会有结果呢????难道只
有ACM才最能体会到那些追逐她的屌丝们内心嘛!!!!)
这个题目是问有多少种情况可以使之符合1/x + 1/y = 1/n ;说实话我本来是想去遍历的,但是惨痛的事实是我们连X最大能取到多大都不知道,连遍历都办不了,n可是10e啊!!!!!!!!!
令y=n+k,那么x=n*n/k+n,也就是问我们到底能有多少种K使之整除,换句话说就是求n*n的因子数目,我们知道根据数分解定理可得任何一个数都可以写成a1^x1*a2^x2*a3^x3.........,其中的a1,a2,a3.。。。。都是素数,而n的因子数目就是(1+x1)(1+x2)(1+x3)*****,而我们是n*n,所以我们就是(1+2*x1)(1+2*x2)(1+2*x3)******,等等,唉我们这样就可以求出来了吗,不是的,我们要进行素数打表时有一个问题需要注意,那就是我们需要求出的素数范围不能是10e,否则就tle了!!!!!!!那应该是多少呢??是sqrt(n),当然了会有人问我如果因子中有数超过了这个呢???就算超过了,也就只有一个会抄过,所以如果最后剩下的那个不是1,那就是大素数了,而它的数目又只是1,所以是(1+2*1)=3;应该乘以三,还有我们算的时候x与y交换只能算一种,要除以2,但是n也是因子之一啊,我们必须加上它做成两个它,再除以二就是了!!!!
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
#define M 40000
int prime[50100];
void table()
{
int i,j;
memset(prime,0,sizeof(prime));
for(i=2; i<=M; i++)
{
//printf("aaa\n");
if(prime[i]==0)
{
//printf("bbbb\n");
for(j=i+i; j<=M; j+=i)
{
prime[j]=1;
// printf("ccc\n");
}
}
}
}
int main()
{
table();
int n,i,j,k,t;
scanf("%d",&t);
int sum;
int e=1;
while(t--)
{
sum=1;
//printf("aaa\n");
scanf("%d",&n);
for(i=2; i<=M; i++)
{
if(n==1)
break;
if(prime[i]==0)
{
k=0;
while(n%i==0)
{
k++;
n=n/i;
}
sum=sum*(2*k+1);
}
}
if(n>1)
sum=sum*3;
printf("Scenario #%d:\n",e);
printf("%d\n\n",(sum+1)/2);
e++;
}
return 0;
}