Coupons UVA
来源:互联网 发布:flash cs6 mac版 编辑:程序博客网 时间:2024/06/14 03:50
推导出最终的式子,然后编程求解即可,注意最大公约数与最小公倍数的使用,具体实现见如下代码:
#include<iostream>#include<vector>#include<string>#include<set>#include<stack>#include<queue>#include<map>#include<algorithm>#include<cmath>#include<iomanip>#include<cstring>#include<sstream>#include<cstdio>#include<deque>#include<functional>using namespace std;typedef long long LL;LL gcd(LL a,LL b){if (!b) return a;return gcd(b, a%b);}LL lcm(LL a,LL b){return a / gcd(a, b)*b;}LL length(LL data){stringstream ss;ss << data;return ss.str().length();}void putChar(int amount,char c){for (int i = 0; i < amount; i++)cout << c;}void getRes(LL left,LL up,LL down){if (up == 0){cout << left << endl;}else{int L1 = length(left);putChar(L1+1,' ');cout << up<<endl;cout << left << " ";int L = length(down);putChar(L,'-');cout << endl;putChar(L1 + 1, ' ');cout << down << endl;}}int main(){LL n;while (cin >> n){if (n == 1){cout << "1\n";}else{LL x=1;for (LL i = 2; i <= n - 1; i++){x = lcm(x,i);}LL up = 0,down=x;for (LL i = 2; i <= n - 1; i++){up += (x / i);}up = up*n;LL c_ud = gcd(up,down);up = up / c_ud, down = down / c_ud;LL left = 1 + n + up / down;getRes(left,up%down,down);}}return 0;}
阅读全文
0 0
- Coupons UVA
- Uva 10288 - Coupons
- UVA 10288 - Coupons
- uva 10288 coupons
- UVA 10288 Coupons
- uva 10288 - Coupons(概率)
- UVA 10288 - Coupons
- UVa 10288 Coupons
- UVA 10288(p333)----Coupons
- uva 10288 Coupons
- uva 10288 Coupons
- Uva 10288 Coupons
- UVA 10288 Coupons
- Coupons - UVa 10288 概率dp
- 【UVA】10288-Coupons(概率)
- uva 10288 Coupons 数学期望
- UVA 10288 Coupons 数学期望
- Coupons
- js 函数调用各种模式详解
- 通过Tomcat的manager app管理web项目
- C#中的Datatable(初步)
- RocketMQ初识
- [BZOJ 2326] 数学作业
- Coupons UVA
- 某一页面强制横屏
- Day 1:Eclipse创建Android模拟器
- JavaScript实现阿拉伯数字和中文数字互相转换
- js验证汉字正则表达式
- SSIS(简单数据抽取过程介绍)
- javascript在闭包中使用this对象
- Eclipse快捷方式
- Eslint 从入门到放弃