結果
| 問題 |
No.1262 グラフを作ろう!
|
| コンテスト | |
| ユーザー |
fastmath
|
| 提出日時 | 2020-10-16 23:40:51 |
| 言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
| 結果 |
TLE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,706 bytes |
| コンパイル時間 | 8,245 ms |
| コンパイル使用メモリ | 256,664 KB |
| 最終ジャッジ日時 | 2025-01-15 10:05:26 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 55 TLE * 41 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcountll
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
#define debug(x) std::cout << #x << ": " << x << '\n';
const int N = 1e6+7;
int pw[N];
bool p[N];
vector <int> d[N];
bool used[N];
int me[N];
int cnt[N];
signed main() {
#ifdef HOME
freopen("input.txt", "r", stdin);
#else
#define endl '\n'
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout.setf(ios::fixed); cout.precision(20);
#endif
for (int i = 1; i < N; ++i)
for (int j = i; j < N; j += i)
d[j].app(i);
for (int i = 2; i < N; ++i)
p[i] = 1;
for (int i = 2; i < N; ++i) {
if (p[i]) {
pw[i] = 1;
for (int j = i * 2; j < N; j += i) {
p[j] = 0;
pw[j]++;
}
}
}
for (int i = 0; i < N; ++i) {
reverse(all(d[i]));
}
int n, m;
cin >> n >> m;
ll ans = 0;
for (int i = 0; i < m; ++i) {
int x;
cin >> x;
if (used[x]) {
ans += me[x];
continue;
}
used[x] = 1;
for (int a : d[x])
cnt[a] = 0;
for (int a : d[x]) {
cnt[a] += x/a;
me[x] += cnt[a] * ((x - 1) % a);
for (int b : d[a])
if (b < a)
cnt[b] -= cnt[a];
}
ans += me[x];
}
cout << ans << endl;
#ifdef HOME
cout << Time << endl;
#endif
}
fastmath