Fractions Again?分数拆分
2015-08-03 11:31
477 查看
汗死,这道题居然卡精度,精度太大或者精度太小都是错1e-4就对了
附上别人博客的测试数据
Out:
代码
附上别人博客的测试数据
3 1 4 15 92 653 589 793 2384 626 4338 3279 502 88
Out:
2 1/3 = 1/12 + 1/4 1/3 = 1/6 + 1/6 1 1/1 = 1/2 + 1/2 3 1/4 = 1/20 + 1/5 1/4 = 1/12 + 1/6 1/4 = 1/8 + 1/8 5 1/15 = 1/240 + 1/16 1/15 = 1/90 + 1/18 1/15 = 1/60 + 1/20 1/15 = 1/40 + 1/24 1/15 = 1/30 + 1/30 8 1/92 = 1/8556 + 1/93 1/92 = 1/4324 + 1/94 1/92 = 1/2208 + 1/96 1/92 = 1/1150 + 1/100 1/92 = 1/621 + 1/108 1/92 = 1/460 + 1/115 1/92 = 1/276 + 1/138 1/92 = 1/184 + 1/184 2 1/653 = 1/427062 + 1/654 1/653 = 1/1306 + 1/1306 5 1/589 = 1/347510 + 1/590 1/589 = 1/18848 + 1/608 1/589 = 1/11780 + 1/620 1/589 = 1/1550 + 1/950 1/589 = 1/1178 + 1/1178 5 1/793 = 1/629642 + 1/794 1/793 = 1/49166 + 1/806 1/793 = 1/11102 + 1/854 1/793 = 1/4514 + 1/962 1/793 = 1/1586 + 1/1586 14 1/2384 = 1/5685840 + 1/2385 1/2384 = 1/2844112 + 1/2386 1/2384 = 1/1423248 + 1/2388 1/2384 = 1/712816 + 1/2392 1/2384 = 1/357600 + 1/2400 1/2384 = 1/179992 + 1/2416 1/2384 = 1/91188 + 1/2448 1/2384 = 1/46786 + 1/2512 1/2384 = 1/40528 + 1/2533 1/2384 = 1/24585 + 1/2640 1/2384 = 1/21456 + 1/2682 1/2384 = 1/11920 + 1/2980 1/2384 = 1/7152 + 1/3576 1/2384 = 1/4768 + 1/4768 5 1/626 = 1/392502 + 1/627 1/626 = 1/196564 + 1/628 1/626 = 1/98595 + 1/630 1/626 = 1/1878 + 1/939 1/626 = 1/1252 + 1/1252 23 1/4338 = 1/18822582 + 1/4339 1/4338 = 1/9413460 + 1/4340 1/4338 = 1/6277086 + 1/4341 1/4338 = 1/4708899 + 1/4342 1/4338 = 1/3140712 + 1/4344 1/4338 = 1/2095254 + 1/4347 1/4338 = 1/1572525 + 1/4350 1/4338 = 1/1049796 + 1/4356 1/4338 = 1/701310 + 1/4365 1/4338 = 1/527067 + 1/4374 1/4338 = 1/352824 + 1/4392 1/4338 = 1/236662 + 1/4419 1/4338 = 1/178581 + 1/4446 1/4338 = 1/120500 + 1/4500 1/4338 = 1/82422 + 1/4579 1/4338 = 1/62419 + 1/4662 1/4338 = 1/43380 + 1/4820 1/4338 = 1/30366 + 1/5061 1/4338 = 1/23859 + 1/5302 1/4338 = 1/17352 + 1/5784 1/4338 = 1/13014 + 1/6507 1/4338 = 1/10845 + 1/7230 1/4338 = 1/8676 + 1/8676 5 1/3279 = 1/10755120 + 1/3280 1/3279 = 1/3587226 + 1/3282 1/3279 = 1/1197928 + 1/3288 1/3279 = 1/13116 + 1/4372 1/3279 = 1/6558 + 1/6558 5 1/502 = 1/252506 + 1/503 1/502 = 1/126504 + 1/504 1/502 = 1/63503 + 1/506 1/502 = 1/1506 + 1/753 1/502 = 1/1004 + 1/1004 11 1/88 = 1/7832 + 1/89 1/88 = 1/3960 + 1/90 1/88 = 1/2024 + 1/92 1/88 = 1/1056 + 1/96 1/88 = 1/792 + 1/99 1/88 = 1/572 + 1/104 1/88 = 1/440 + 1/110 1/88 = 1/330 + 1/120 1/88 = 1/264 + 1/132 1/88 = 1/209 + 1/152 1/88 = 1/176 + 1/176
代码
#include<iostream> #include<cstdio> #include<algorithm> #include<cstring> #include<cmath> using namespace std; int main() { int n; int sum;int i; while(scanf("%d",&n)!=EOF) { sum=0; double x=(double)n; double y,temp; for(i=n+1;i<=2*n;i++) { temp=double(i); y=1/x-1/temp; if(fabs((1/y)-int(1/y+0.5))<=1e-4) { sum++; } } printf("%d\n",sum); int ok=0; for(i=n+1;i<=2*n;i++) { temp=double(i); y=1/x-1/temp; double xx=1/y+0.5; if(fabs((1/y)-int(xx))<=1e-4) { ok++; int dx=int(xx); printf("1/%d = 1/%d + 1/%d\n",n,dx,i); } } } return 0; }
相关文章推荐
- POJ - 1363 - Rails(栈)
- 用CorePlot实现类似Air Quality的柱状图滚动效果(1/2)
- HDU 2476 区间DP String painter
- POJ 1273 --Drainage Ditches【最大流模板 && dinic】
- openstack keypair实践
- DllMain和多线程死锁
- MacBook Air响一声白屏故障情况说明及解决
- Failed to start monitoring XXXXX\web.config because access was denied
- 解决nginx: [error] open() "/usr/local/nginx/logs/nginx.pid" failed错误
- (FFOS Gecko & Gaia) IPC - 一种“猥琐的”IPC方式
- NSURLSession的代理为什么使用retain?
- OpenSCManager failed - 拒绝访问
- Windows环境下main()函数传入参数
- 杭电oj1789 Doing Homework again(贪心与队列完美碰撞)
- [2015hdu多校联赛补题]hdu5293 Tree chain problem
- Check GitLab API access: FAILED: Failed to connect to internal API
- public static void main(String arg[]) 详细解释
- bower failed: UNABLE_TO_VERIFY_LEAF_SIGNATURE
- 70. Climbing Stairs
- repair windows ntfs part on ubuntu