UVA10288Coupons
来源:互联网 发布:淘宝退款能申请几次 编辑:程序博客网 时间:2024/06/10 05:23
//UVA10288Coupons#include<cstdio>#include<cstring>#include<sstream>#include<iostream>using namespace std;typedef long long LL;LL Gcd(LL a, LL b) { return b == 0 ? a : Gcd(b, a % b);}LL Lcm(LL a, LL b) {return a / Gcd(a, b) * b;}LL get_len(LL c) {stringstream ss;ss << c;return ss.str().length();}void print_chars(LL len, char c) {while(len--) putchar(c);}void print(LL a, LL b, LL c) {if(b == 0) {printf("%lld\n", a); return;}LL a_len = get_len(a);print_chars(a_len + 1, ' '); printf("%lld\n", b);LL c_len = get_len(c);printf("%lld ", a); print_chars(c_len, '-'); printf("\n");print_chars(a_len + 1, ' '); printf("%lld\n", c);}int main() {int n;while(scanf("%d", &n) == 1) {if(n == 1) {print(1, 0, 0); continue;}LL x = 2, b = 0;for(int i = 2; i <= n - 1; i++) x = Lcm(x, i);//LL c = x;for(int i = 2; i <= n - 1; i++) b += c / i;//通分后分子的一部分b *= n;x = Gcd(b, c);b /= x; c /= x;//约分 LL a = 1 + n + b / c;/*用n去乘公式中的1和1/n*/ b %= c;//化为带分数 print(a, b, c); }return 0;}/*2517*/
阅读全文
0 0
- UVA10288Coupons
- 牛客网刷题知识点总结(六)java web
- NSArray 冷知识
- 使select option达到超链接的效果实例
- Android PowerImageView实现,可以播放动画的强大ImageView
- python IDE(集成开发环境) pycharm-professional 安装 注册
- UVA10288Coupons
- Linux网络
- MySql存储引擎
- USACO Section 1.3 Barn Repair
- 数据结构实验之排序二:交换排序
- HDU 6097 Mindis【几何】
- Android进程保活招式大全
- Laravel : Syntax error or access violation: 1055 Error
- zookeeper的单机和伪集群myid中的数字是唯一标识