hdu 1299 Diophantus of Alexandria (数论)
Diophantus of Alexandria
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2269 Accepted Submission(s): 851
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?
first line contains the number of scenarios. Each scenario consists of
one line containing a single number n (1 ≤ n ≤ 10^9).
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.
//140MS 200K 622 B G++
#include<stdio.h>
#include<math.h>
long long solve(int n)
{
long long ans=;
int i;
int m=(int)sqrt(n+0.5);
for(i=;i<=m;i++){
int ret=;
if(n%i==){
n/=i;
while(n%i==){
n/=i;ret++;
}
ans*=(*ret+);
}
if(n<i) break;
}
if(n>) ans*=;
return ans;
}
int main(void)
{
int n;
int cas=,t;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
printf("Scenario #%d:\n%lld\n",cas++,solve(n)/+);
printf("\n");
}
return ;
}
hdu 1299 Diophantus of Alexandria (数论)的更多相关文章
- hdu 1299 Diophantus of Alexandria(数学题)
题目链接:hdu 1299 Diophantus of Alexandria 题意: 给你一个n,让你找1/x+1/y=1/n的方案数. 题解: 对于这种数学题,一般都变变形,找找规律,通过打表我们可 ...
- 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+ ...
- 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 ...
- HDU 1299 基础数论 分解
给一个数n问有多少种x,y的组合使$\frac{1}{x}+\frac{1}{y}=\frac{1}{n},x<=y$满足,设y = k + n,代入得到$x = \frac{n^2}{k} + ...
- hdu Diophantus of Alexandria(素数的筛选+分解)
Description Diophantus of Alexandria was an egypt mathematician living in Alexandria. He was one of ...
- Hdu 1299
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 ...
- Diophantus of Alexandria
Diophantus of Alexandria was an egypt mathematician living in Alexandria. He was one of the first ma ...
随机推荐
- 查询sql2005&2008全部表信息
如果是查询sql server ,把sys.extended_properties修改为SysProperties SELECT 表名 THEN D.NAME ELSE '' END, 表说明 THE ...
- AE开发示例之GPBufferLayer
using System; using System.Drawing;using System.Text;using System.Windows.Forms;using System.Runtime ...
- 解决oracle 中文入库是乱码的问题
增加两个环境变量: LANG=zh_CN.GBK NLS_LANG = SIMPLIFIED CHINESE_CHINA.ZHS16GBK
- Log.properties配置详解
一.Log4j简介 Log4j有三个主要的组件:Loggers(记录器),Appenders (输出源)和Layouts(布局).这里可简单理解为日志类别,日志要输出的地方和日志以何种形式输出.综合使 ...
- crontab 提示 command not found 解决方案
今天遇见一个问题,crontab的定时任务会报错:java command not found,但是手动执行脚本一直能成功. 猜想是环境变量的问题. 在crontab里添加个打印环境变量的任务: * ...
- 自动检测浏览器是手机还是pc
function CheckBrower() { if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) { //判断iPhone|iPad| ...
- android第二天(项目的组成结构)
1:src文件夹分析: helloWorld----src(源码文件夹) MainActivity:主界面类----gen(自动生成的源码文件夹) R.java:对应res文件夹 下面又包含三个内部类 ...
- SQL Server 2012 AlwaysOn 亲身实历记
亲身经历的一个项目,老板忽然提出,对数据库的负债要实施分流,来个数据库一个负责读,而另一个负责写,后台是需要同步两个数据库的状态.找了很多的资料,发现新版的alwayson可以实现这个功能. 研读了a ...
- C# iis错误配置信息( 500.21 - Internal Server Error )
新电脑安装完开发环境后,还需要注册framework4.0到IIS.不然会报错: HTTP 错误 500.21 - Internal Server Error 处理程序"Extensionl ...
- 使用js脚本批量下载慕课网视频
慕课网(http://www.imooc.com/)上有很多不错的视频,当然我不是来给慕课网打广告的,我本人学习过很多慕课网上的免费的视频. 在线看如果网速慢时,可能会有卡顿,没网时无法观看.所有说下 ...