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 ...
随机推荐
- Oracle数据库监听服务无法启动
(1) 安装好Oracle后,启动Net Manager,测试orcl失败,报错“ORA-12514: TNS: 监听程序当前无法识别连接描述符中请求的服务”,需要修改监听文件.修改前: # list ...
- Nice Validator(Form验证)及Juery zTree控件
http://niceue.com/validator/demo/match.php http://www.ztree.me/v3/demo.php#_603
- OpenGL学习笔记2——顶点数组
#pragma comment(lib,"glut32.lib") #pragma comment(lib,"glut.lib") #pragma commen ...
- cocos2d触碰例子代码
// // TestLayer.h // MiniTD // // Created by OnePiece on 12-7-30. // Copyright 2012年 __MyCompanyName ...
- c# 文件及目录操作类
18位长度的计时周期数: DateTime.Now.Ticks.ToString() 多数是收集而来,加上测试感觉很不错,分享一下或许有些帮助吧: 引用: using System; using Sy ...
- ionic tabs置顶
找了好久怎么解决这问题,终于找到了一哥们留下来的经验,万分感谢,特此拷贝过来,留着下次以免忘记 我在主页ion-nav-bar元素上添加hide-nav-bar=“true”;然后又在ion-view ...
- 自增长主键Id的另类设计
一.引言 在使用ORM框架时,一个表有一个主键是必须的,如果没有主键,就没有办法来唯一的更新一条记录.在Sql Server数据库和Mysql数据库设置自增长的主键是一件很轻松的事情,如果在Oracl ...
- Samba 4 Domain Controller on Ubuntu 14.04 LTS
1. Configure network with a static ip address $sudo nano /etc/network/interfaces auto eth0 iface eth ...
- 1219 spring3 项目总结
Spring3 项目总结 列志华 (组长) http://www.cnblogs.com/liezhihua/ 团队guihub https://github.com/LWHTF/OrderingFo ...
- 游戏笔记之《Fez》
FEZ 游戏名称:菲斯 英文名称:Fez 游戏类型:ACT(动作游戏),AVG(冒险游戏) 游戏制作:Polytron Corporation 游戏发行:Trapdoor 游戏平台:PC 游戏画面: ...