紫书 例题7-3 UVA 10976
来源:互联网 发布:socket异步收发数据 编辑:程序博客网 时间:2024/04/30 05:20
【题意】给你一个数k,求所有使得1/k = 1/x + 1/y成立的x≥y的整数对。
【解题方法】数论,枚举。枚举所有在区间(k+1,2k)上的y即可,当1/k - 1/y的结果分子为1即为一组解。
【AC代码】
////Created by just_sort 2016/1/3//Copyright (c) 2016 just_sort.All Rights Reserved//#include <ext/pb_ds/assoc_container.hpp>#include <ext/pb_ds/tree_policy.hpp>#include <ext/pb_ds/hash_policy.hpp>#include <set>#include <map>#include <queue>#include <stack>#include <cmath>#include <cstdio>#include <time.h>#include <cstdlib>#include <cstring>#include <sstream> //isstringstream#include <iostream>#include <algorithm>using namespace std;using namespace __gnu_pbds;typedef long long LL;typedef pair<int, LL> pp;#define REP1(i, a, b) for(int i = a; i < b; i++)#define REP2(i, a, b) for(int i = a; i <= b; i++)#define REP3(i, a, b) for(int i = a; i >= b; i--)#define CLR(a, b) memset(a, b, sizeof(a))#define MP(x, y) make_pair(x,y)const int maxn = 100;const int maxm = 2e5;const int maxs = 10;const int INF = 1e9;const int UNF = -1e9;const int mod = 1e9+7;int gcd(int x, int y) {return y == 0 ? x : gcd(y, x % y);}//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>order_set;//headint a[10010];int main(){ int k; while(scanf("%d", &k) != EOF) { int cnt = 0; REP2(y, 1, 2 * k){ if(y == k) continue; if((abs(k * y) % abs(y - k) == 0) && ((k * y) / (y - k) >= y)){ a[++cnt] = y; } } printf("%d\n", cnt); REP2(i, 1, cnt){ printf("1/%d = 1/%d + 1/%d\n", k, (k * a[i]) / (a[i] - k), a[i]); } } return 0;}
0 0
- 紫书 例题7-3 UVA 10976
- 例题 7-3 分数拆分 UVa 10976
- UVa 10976 Fraction Again?! 分数拆解 (例题7-3)
- 例题7-3 分数拆分(Fractions Again?!, UVa 10976)
- 紫书 例题7-7 UVA 1354
- 紫书 例题7-1 UVA 725
- 紫书 例题7-4 UVA 524
- 紫书 例题7-5 UVA 129
- 紫书 例题7-6 UVA 140
- 紫书 例题7-8 Uva 10603 BFS
- 紫书 例题 7-11 宝箱 UVA 12325
- UVA 11464 例题7
- 例题6-3 UVa
- 紫书动规 例题9-7 UVA
- 紫书动规 例题9-3 UVA
- 例题9-3 UVa 1347
- UVA #725 #11059 #10976 (例题7-1 7-2 7-3)
- 紫书 例题7-2 UVA 11059 暴力枚举
- 紫书 例题7-2 UVA 11059 暴力枚举
- [Medium]Integer Break
- 图像特征提取三大法宝:HOG特征,LBP特征,Haar特征
- static类成员使用注意
- [Medium]Counting Bits
- 紫书 例题7-3 UVA 10976
- 工业网络空间安全态势分析报告
- python windows扩展包
- Window 7下 MongoDB 的安装应用简析
- Android实现动画效果之淡入淡出
- [Medium]Coin Change
- Linux安装Mongodb
- c语言学习笔记(标准文件io)
- linux 使用 ----如何让虚拟机上网(vmware)