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?
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
代码:
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
#define M 50005
int prime[50005];
void db()
{
int i,j;
memset(prime,0,sizeof(prime));
for(i=2; i<=M; i++)
{
if(prime[i]==0)
{
for(j=i+i; j<=M; j+=i)
{
prime[j]=1;
}
}
}
}
int main()
{
db();
int n,i,j,k,t;
scanf("%d",&t);
int sum;
int cnt=1;
while(t--)
{
sum=1;
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",cnt);
printf("%d\n\n",(sum+1)/2);
cnt++;
}
return 0;
}
Diophantus of Alexandria的更多相关文章
- hdu 1299 Diophantus of Alexandria (数论)
Diophantus of Alexandria Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java ...
- Diophantus of Alexandria[HDU1299]
Diophantus of Alexandria Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Ot ...
- hdu Diophantus of Alexandria(素数的筛选+分解)
Description Diophantus of Alexandria was an egypt mathematician living in Alexandria. He was one of ...
- hdu 1299 Diophantus of Alexandria(数学题)
题目链接:hdu 1299 Diophantus of Alexandria 题意: 给你一个n,让你找1/x+1/y=1/n的方案数. 题解: 对于这种数学题,一般都变变形,找找规律,通过打表我们可 ...
- hdoj 1299 Diophantus of Alexandria
hdoj 1299 Diophantus of Alexandria 链接:http://acm.hdu.edu.cn/showproblem.php?pid=1299 题意:求 1/x + 1/y ...
- 数学--数论--HDU 1299 +POJ 2917 Diophantus of Alexandria (因子个数函数+公式推导)
Diophantus of Alexandria was an egypt mathematician living in Alexandria. He was one of the first ma ...
- Diophantus of Alexandria(唯一分解定理)
Diophantus of Alexandria was an Egypt mathematician living in Alexandria. He was one of the first ma ...
- hdu 1299 Diophantus of Alexandria
1/x + 1/y = 1/n 1<=n<=10^9给你 n 求符合要求的x,y有多少对 x<=y// 首先 x>n 那么设 x=n+m 那么 1/y= 1/n - 1/(n+ ...
- hdu-1299 Diophantus of Alexandria(分解素因子)
思路: 因为x,y必须要大与n,那么将y设为(n+k);那么根据等式可求的x=(n2)/k+n;因为y为整数所以k要整除n*n; 那么符合上面等式的x,y的个数就变为求能被n*n整除的数k的个数,且k ...
随机推荐
- windows下查看端口占用(砖)
第一步,执行命令:netstat -ano -a 显示所有连接和监听端口 -n 以数字形式显示地址和端口号. 此选项一般与 -a选项组合使用 -o 显示与每个连接相关的所属进程 ID. Active ...
- C#操作JSON专题
第一章:C#如何拿到从http上返回JSON数据? 第二章:C#如何解析JSON数据?(反序列化对象) 第三章:C#如何生成JSON字符串?(序列化对象) 第四章:C#如何生成JSON字符串提交给接口 ...
- Velocity加载模版文件
一.类路径 加载classpath目录下的vm文件,或者maven项目的resources路径下 Properties p = new Properties(); p.put("file.r ...
- C程序设计语言(K&R) 笔记1
当作复习... (1)将华氏度 换算成 摄氏度,公式: ℃=(5/9)(̧°F-32) #include <stdio.h> int transformTemprature(int F){ ...
- 基于aspectj的aop注解操作
- php5.6,curl上传的变化
$ch = curl_init ();curl_setopt ( $ch, CURLOPT_SAFE_UPLOAD, false); //php5.6要加上这个 $fields = array(); ...
- Codeforces #505(div1+div2) B Weakened Common Divisor
题意:给你若干个数对,每个数对中可以选择一个个元素,问是否存在一种选择,使得这些数的GCD大于1? 思路:可以把每个数对的元素乘起来,然后求gcd,这样可以直接把所有元素中可能的GCD求出来,从小到大 ...
- C++获取电脑上连接的多个摄像头名称与编号
#include<iostream>#include "strmif.h"#include <initguid.h>#include<vector&g ...
- Windows系统 安装 Qt 5.7.0
Windows系统 安装 Qt 5.7.0 我们的电脑系统:Windows 10 64位 Qt5 软件:Qt 5. 7. 0 下载 Qt 5.7.0 软件 在这个网站里面,下载:Qt 5.7.0 fo ...
- 64位系统中fatal error: stdio.h: 没有那个文件或目录的错误的解决方法
Ubuntu系统中可输入如下命令,安装开发环境: sudo apt-get install build-essential https://blog.csdn.net/yygydjkthh/artic ...