# 简单高精度

xiaoxiao2021-03-01  8

#### L1-6 整除光棍（20 分）

31

3584229390681 15

#include <bits/stdc++.h> using namespace std; int x, k = 0, ans[1000000]; string s; bool cal() { int t = 0; k = 0; for(int i = 0; i < s.size(); i++){ t = t * 10 + s[i] - '0'; if(k || t >= x)//就是这，我一开始是t>=x所以导致一直没拿全分数 { ans[k++] = t / x; t %= x; } } if(t == 0) return 0; return 1; } int main() { cin >> x; s = "1"; while(cal()) s += "1"; for(int i = 0; i < k; i++) cout << ans[i]; cout << " " << s.size() << endl; return 0; } #include <bits/stdc++.h> using namespace std;// 我的模仿 string s; int ans[2000005]; int t,x; int num; bool check(){ ans[num++] = t/x; if (t < x)return true; t = t%x; if(t==0) return false; return true; } int main() { ios::sync_with_stdio(false); cin >> x; s = "1"; t = 1; while (check()){ s += "1"; t = t*10+1; } int i; for (i = 0;i < num;i ++){ if (ans[i] != 0)break; } for (;i < num;i ++) cout << ans[i]; cout << ' ' << s.size() << endl; } 哇，还有一个方法 #include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int flag = 0; int i; int x = 0; for(i = 1;; i ++) { x = x*10 + 1; if (x >= n){ flag = 1; cout << x/n; } else if (flag) { cout << 0; } x = x%n; if(x == 0) break; } cout << " " << i <<endl; // cout << "Hello world!" << endl; return 0; }