結果
| 問題 |
No.1036 Make One With GCD 2
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-04-24 21:57:22 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 782 ms / 2,000 ms |
| コード長 | 1,267 bytes |
| コンパイル時間 | 2,186 ms |
| コンパイル使用メモリ | 192,704 KB |
| 最終ジャッジ日時 | 2025-01-09 23:40:01 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 41 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:29:21: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
29 | int n; scanf("%d", &n);
| ~~~~~^~~~~~~~~~
main.cpp:30:24: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
30 | REP(i, n) scanf("%lld", a[i]);
| ~~~~~^~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
template<typename T>
using pque = priority_queue<T, vector<T>, greater<T>>;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif
constexpr int N = 512345, M = 20;
ll a[N][M];
int main(){
int n; scanf("%d", &n);
REP(i, n) scanf("%lld", a[i]);
FOR(i, n, N) a[i][0] = 1;
FOR(i, 1, M){
REP(j, n){
int k = j + (1<<(i-1));
if(k >= N) continue;
a[j][i] = gcd(a[j][i-1], a[k][i-1]);
}
}
DEBUG("constructed\n");
ll ans = 0;
REP(i, n){
ll z = 0;
int j = i;
for(int k = M-1; k >= 0; k--){
int jj = j + (1<<k);
if(jj > n) continue;
ll zz = gcd(z, a[j][k]);
DEBUG(" gcd[%d, %d) = %lld -> %lld\n", j, jj, a[j][k], z);
if(zz > 1) {
j = jj;
z = zz;
}
}
DEBUG("[%d, %d)\n", i, j);
ans += n-j;
}
printf("%lld\n", ans);
}