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 ...
随机推荐
- BAE log服务的配置(nodejs)
log4js.loadAppender('baev3-log'); var options = { 'user': appConfig.AK, //这里是在用户的安全认证中的Access Key ID ...
- Converter转换器使用
package com.xu.javabean; import java.lang.reflect.InvocationTargetException; import java.util.Date; ...
- c# 文件及目录操作类
18位长度的计时周期数: DateTime.Now.Ticks.ToString() 多数是收集而来,加上测试感觉很不错,分享一下或许有些帮助吧: 引用: using System; using Sy ...
- centos7 下修改时区
#timedatectl status //显示当前设置 #timedatectl list-timezones //列出时区 #timedatectl set-timezone Asia/Shang ...
- WinCE\Window Mobile程序桌面化总结
1.系统API处理 将桌面.移动API分开处理 2.一份代码,两个工程,分别编译 添加已有文件时,使用添加链接,而不是添加附本 3.桌面窗体出现位置不规律,样式不统一问题 首先,在窗体类成员加入两个成 ...
- .net 中select和where的区别
Select(p=>p.ID==id) 这里选择的结果是通过p,访问迭代器,然后选取的是p.ID==id的结果,选择到的是bool对象 Where(p=>p.ID==id) 这里是过滤,p ...
- Neo4j创建自动索引
一.创建Neo4j的Legacy indexing 1.为节点创建索引 官方API的创建示例为: 将一节点添加至索引: public static void AddNodeIndex(String n ...
- FreeMark学习(三)
沉淀的心 freemarker学习笔记--设计指导 <# ... > 中存放所有freemaker的内容,之外的内容全部原样输出.<@ ... /> 是函数调用两个定界 ...
- JAVA学习笔记(1-32)
1:数据的输入中,也需要提前声明变量.java区分大小写,注意保留字的问题,注意分号. 2:用import调用一个类.用new新建一个对象,相当于c中的malloc. 3:用final定义一个宏,相当 ...
- Nuget版本冲突的问题
有两个类库项目,一个引用了比如Newtonsoft.Json 6.0, 另一个引用了比如Newtonsoft.Json 8.0, 然后另一个exe项目同时引用了这两个类库项目. 那么在编译的时候会报w ...