BITACM 1050 Diophantus of Alexandria
来源:互联网 发布:linux vim python配置 编辑:程序博客网 时间:2024/04/29 08:47
题目大意:给定你一个n,问你有多少对x,y满足1/x+1/y=1/n。
首先,x,y>n。
我们设x=n+k(k>0)。
那么1/y=1/n-1/(n+k)=k/(n^2+k*n)
注意到y一定是整数,所以可以考虑把k除下来。
那么(n^2+k*n)/k一定是一个整数。
那么k|n^2。
k的个数一定是奇数个,考虑到x,y的大小问题。最后的答案应该是k的个数加1再除以2。
那么n^2的因子个数是多少个?
先考虑n的因数分解,由唯一分解定理,假设n=p1^k1*p2^k2*p3^k3....
那么n的因子个数就应该是(k1+1)*(k2+1)*(k3+1)*....(对于每个质因数我们都有ki+1种选法,由乘法原理可得)
附:假设x<=y,那么n+k<=(n^2+k*n)/k
化简:k^2+k*n<=n^2+k*n
再化简:k<=n。
#include "cstdio"#include <cmath>#define LL long longint main(){ int kase=1; int T; LL ans; LL n; int cnt; LL tem; scanf("%d",&T); while(T--){ scanf("%lld",&n); ans=1; tem=n; for(int i=2;i<=sqrt(tem+0.5);i++){ if(n%i==0){ cnt=0; while(n%i==0){ cnt++; n/=i; } ans*=(2*cnt+1); } } if(n!=1) ans*=3; printf("Scenario #%d:\n%lld\n\n",kase++,(ans+1)/2); } return 0;}
0 0
- BITACM 1050 Diophantus of Alexandria
- 2013寒假练习 1050 Diophantus of Alexandria
- hdu1299.Diophantus of Alexandria
- HDU_1299 Diophantus of Alexandria
- hdu1299 Diophantus of Alexandria
- Diophantus of Alexandria
- HDU1299 Diophantus of Alexandria
- Diophantus of Alexandria
- HDU1299-Diophantus of Alexandria
- Diophantus of Alexandria HDU
- HDU 1299 Diophantus of Alexandria
- poj 2917 Diophantus of Alexandria
- HDU 1299 Diophantus of Alexandria
- Hdu 1299 (Diophantus of Alexandria)
- Hdu 1299 Diophantus of Alexandria
- POJ 2917 Diophantus of Alexandria
- Hoj 2305 Diophantus of Alexandria
- hdoj 1299 Diophantus of Alexandria
- day43 spring aop_2
- [编程之美] 2.4 1的个数
- JAVA中文乱码解决
- 3.6 周四 数据结构
- android 获取 ip 地址方法
- BITACM 1050 Diophantus of Alexandria
- Oracle交互命令方式导出
- WAMPServer默认配置更改-web根目录
- 第十二天3月5日之用户注册案例
- Source Insight中使用正则表达式进行高级替换
- 小米三年市值300亿,雷军二次创业为何如此成功?
- 黑马程序员_HTML+JSP:注册表单
- 一个 fork 的面试题
- 中国足球,真的是扶不起的阿斗?