//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;
}
/*
2
5
17
*/
UVA10288Coupons
最新推荐文章于 2018-10-15 20:48:33 发布