hdu 1299 Diophantus of Alexandria(数学题)
题目链接:hdu 1299 Diophantus of Alexandria
题意:
给你一个n,让你找1/x+1/y=1/n的方案数。
题解:
对于这种数学题,一般都变变形,找找规律,通过打表我们可以发现这个答案只与这个数的因子有关。
n=a1^p1*a2^p2*...*an^pn
ans=((1+2*p1)*(1+2*p2)*...*(1+2*pn)+1)/2
#include<bits/stdc++.h>
#define F(i,a,b) for(int i=a;i<=b;++i)
using namespace std; const int N=1e5+;
int primes[N],tot=;
bool vis[N];
void Euler(){
F(i,,N-){
if(!vis[i])primes[++tot]=i;
F(j,,tot){
if(i*primes[j]>N)break;
vis[i*primes[j]]=;
if(i%primes[j]==)break;
}
}
} int t,n,ans,cas; int main()
{
Euler();
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
ans=;
F(i,,tot)
{
if(primes[i]>n)break;
int cnt=;
while(n%primes[i]==)n/=primes[i],cnt++;
ans*=*cnt+;
}
if(n>)ans*=;
printf("Scenario #%d:\n%d\n\n",++cas,(ans+)/);
}
return ;
}
hdu 1299 Diophantus of Alexandria(数学题)的更多相关文章
- hdu 1299 Diophantus of Alexandria (数论)
Diophantus of Alexandria Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java ...
- 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 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 ...
- HDU 1299 基础数论 分解
给一个数n问有多少种x,y的组合使$\frac{1}{x}+\frac{1}{y}=\frac{1}{n},x<=y$满足,设y = k + n,代入得到$x = \frac{n^2}{k} + ...
- Diophantus of Alexandria
Diophantus of Alexandria was an egypt mathematician living in Alexandria. He was one of the first ma ...
随机推荐
- windows下mysql备份、还原,使用mysqldump
直接备份 mysqldump -u用户名 -p密码 -h 192.168.1.15 -c --default-character-set=utf8 数据库名>xxx.sql 使用gz ...
- Zabbix监控系统功能及基本使用
一.Zabbix基本介绍: zabbix是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案.它能监视各种网络参数,保证服务器系统的安全运营:并提供柔软的通知机制以让系 ...
- ExpandoObject,DynamicObject,DynamicMetaObject
ExpandoObject,DynamicObject,DynamicMetaObject 接上文:浅谈Dynamic关键字系列之三(上) 为什么TryXXX方法没有被调用?? 将DynamicPro ...
- Effective C++(19) 设计class犹如设计type
问题聚焦: 这一节不涉及代码,但是我们需要明确的一点是,思想比代码要重要得多. 设计优秀的classes是一项艰巨的工作,就像设计好的types一样. 我们应该带着和“语言设计 ...
- SSDB是一个开源的高性能数据库服务器
SSDB是一个开源的高性能数据库服务器, 使用Google LevelDB作为存储引擎, 支持T级别的数据, 同时支持类似Redis中的zset和hash等数据结构, 在同时需求高性能和大数据的条件下 ...
- HTML5-WebSocket-初探
1.环境准备 主要是用<HTML5 程序设计>(第二版)作为学习参考资料.但是上面用的WebSocket服务器是用python写的.偶不懂python,于是得找另外一个替代实现,这里适用n ...
- uva 408 Uniform Generator
Uniform Generator Computer simulations often require random numbers. One way to generate pseudo-ran ...
- js冒泡排序和二分查找
冒泡排序: var arr=[5,0,-56,900,12,9000,-123,-1000]; var flag=false; for(var i=0;i<arr.length-1;i++){ ...
- javascript计算字符串中出现最多的字符和个数
代码如下: <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <t ...
- .NET接口和类 反射的差异性发现
1 背景 在项目中使用反射,反射出某类型的所有属性(Property)和对应的属性值.起初为了性能考虑在模块首次加载就反射类型的所有属性并将其存入字典.根据一般的编程规范——基于接口编程,所以首次传入 ...