1 条题解
-
0蔡竣凯 LV 6 @ 2022-4-18 19:58:18
#include<iostream> #include<cmath> #include<algorithm> #include<cstdio> #include<cstring> using namespace std; typedef long long LL; const int MAXN = 1e5 + 10; const int INF = 0x3f; int n; LL p, q = 1, r; inline long long gcd(LL a,LL b){ if(b == 0)return a; else return gcd(b, a % b); } inline int s(LL x){ int p = 0; while(x > 0){ x /= 10; p++; } return p; } int main() { cin >> n; for(int i = 1;i <= n; i++){ p = p * i + q * n; q *= i; r = gcd(p, q); p /= r; q /= r; } r = p/q; p %= q; if(p == 0)cout << r << "\n"; else{ for(int i = s(r);i > 0; i--)cout << " "; cout << p << endl; if(r > 0)cout << r; for(int i = s(q);i > 0; i--)cout << "-"; cout << endl; for(int i = s(r);i > 0; i--)cout << " "; cout << q << "\n"; } return 0; }
- 1
信息
- ID
- 1847
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 10
- 标签
- 递交数
- 3
- 已通过
- 2
- 上传者