题解:AT_agc070_a [AGC070A] Multiples in the String
Jasonbenji · · 题解
题解:AT_agc070_a [AGC070A] Multiples in the String
首先观察到
如何重叠会最多呢?这让我们想到经典的
于是我们要探查一下
换句话说,我们想找一个数
int x = 1;
while (true) {
x = x * 10 % Z;
if (x == 1)
break;
}
的过程中,程序能在有限时间内结束且
:::info[打表找
#include <bits/stdc++.h>
using namespace std;
bool np[10001];
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
for (int i = 2; i <= 10000; i++) {
if (!np[i] && i > 1000) {
int cnt = 1, now = 9;
while (now) {
cnt++;
now = (now * 10 + 9) % i;
}
if (cnt == i - 1)
cout << i << ':' << cnt << '\n';
}
for (int j = i + i; j <= 10000; j += i)
np[j] = true;
}
return 0;
}
:::
:::success[AC code]
#include <bits/stdc++.h>
using namespace std;
constexpr int P = 1019;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
vector<int> ans;
int now = 1;
for (int i = 1; i < P; i++) {
now = now * 10;
ans.push_back(now / P);
now = now % P;
}
for (int i : ans)
cout << i;
cout << '\n';
for (int i : ans)
cout << i;
for (int i : ans)
cout << i;
cout << '\n';
return 0;
}
:::