hdu 1299 Diophantus of Alexandria
来源:互联网 发布:nagios 监控windows 编辑:程序博客网 时间:2024/04/27 14:25
题意:输入n,问存在多少对(x,y),符合1/x+1/y=1/n,其中x<=y。
题解:变换下公式,得到y=(n*x)/(x-n),令a=x-n,则y=n*(n+a)/a=n*n/a+n。所以只要a是n^2的因子符合条件。直接计算n^2的因子数,必定超时。所以我们想到n的某个质因子个数为k,则n^2的质因子个数为2*k,这个很容易理解。而有个定理:一个数的因子数等于各个质因子个数+1的乘积。如24=2*2*2*3,因子数为(3+1)*(1+1)=8;这个忘了是什么定理的,反正一直在用就是了。。
若n的质因子个数分别为p1,p2,p3...,pk。则ans=(p1*2+1)*(p2*2+1)*...*(pk*2+1);
还要除去重复的。而必定存在一对x=y,使得方程成立;且x和y的顺序和结果无关(交换x和y结果不变)。所以答案就是ans/2+1。
耗时:171MS
#include <cstdio>#include <cstring>#include <cmath>#include <queue>#include <iostream>#include <algorithm>using namespace std;#define LL __int64int main(){ int T,tt=0; cin>>T; while(T--) { int n,ans=1,i,t=0,m; cin>>n; m=(int)sqrt(n+0.5); for(i=2;i<=m;i++) { if(n%i==0) { while(n%i==0){n=n/i;t++;} ans=ans*(t*2+1); t=0; } } if(n>1) ans*=3; cout<<"Scenario #"<<++tt<<":"<<endl; cout<<ans/2+1<<endl<<endl; } return 0;}
- HDU 1299 Diophantus of Alexandria
- HDU 1299 Diophantus of Alexandria
- Hdu 1299 (Diophantus of Alexandria)
- Hdu 1299 Diophantus of Alexandria
- hdu 1299 Diophantus of Alexandria
- hdu 1299 Diophantus of Alexandria
- HDU 1299 Diophantus of Alexandria
- hdu 1299 Diophantus of Alexandria
- HDU 1299 Diophantus of Alexandria
- HDU 1299 Diophantus of Alexandria
- HDU 1299 Diophantus of Alexandria
- hdu 1299 Diophantus of Alexandria
- 【HDU】 1299 Diophantus of Alexandria
- Diophantus of Alexandria HDU
- HDU/HDOJ 1299 Diophantus of Alexandria
- HDU 1299 Diophantus of Alexandria(数论)
- HDU 1299 Diophantus of Alexandria (数论)
- hdu 1129 Diophantus of Alexandria
- 编辑距离,最长公共子序列,最长公共子串,最长递增子序列
- suse linux集群加入AD域问题
- 日期工具类
- char*和CString转换
- 面试总结
- hdu 1299 Diophantus of Alexandria
- Android开发小问题——java使用
- 在MFC中使用Qt生成的DLL
- 曾经的足迹——对Linux CAN驱动的理解(1)
- 回车与换行的区别
- WinDBG之SOSEX扩展
- hdu
- 云南大学新一届俱乐部会员招新
- oracle索引总结