結果

問題 No.2552 Not Coprime, Not Divisor
ユーザー ochiaigawaochiaigawa
提出日時 2023-11-25 14:58:00
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,983 ms / 2,000 ms
コード長 1,038 bytes
コンパイル時間 2,338 ms
コンパイル使用メモリ 205,228 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2023-11-25 14:58:21
合計ジャッジ時間 20,399 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 620 ms
6,676 KB
testcase_01 AC 1,417 ms
6,676 KB
testcase_02 AC 490 ms
6,676 KB
testcase_03 AC 1,397 ms
6,676 KB
testcase_04 AC 1,403 ms
6,676 KB
testcase_05 AC 140 ms
6,676 KB
testcase_06 AC 1,555 ms
6,676 KB
testcase_07 AC 1,849 ms
6,676 KB
testcase_08 AC 1,097 ms
6,676 KB
testcase_09 AC 1,983 ms
6,676 KB
testcase_10 AC 445 ms
6,676 KB
testcase_11 AC 897 ms
6,676 KB
testcase_12 AC 1,918 ms
6,676 KB
testcase_13 AC 553 ms
6,676 KB
testcase_14 AC 319 ms
6,676 KB
testcase_15 AC 2 ms
6,676 KB
testcase_16 AC 2 ms
6,676 KB
testcase_17 AC 252 ms
6,676 KB
testcase_18 AC 2 ms
6,676 KB
testcase_19 AC 2 ms
6,676 KB
testcase_20 AC 2 ms
6,676 KB
testcase_21 AC 2 ms
6,676 KB
testcase_22 AC 2 ms
6,676 KB
testcase_23 AC 2 ms
6,676 KB
testcase_24 AC 2 ms
6,676 KB
testcase_25 AC 2 ms
6,676 KB
testcase_26 AC 2 ms
6,676 KB
testcase_27 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;

int main() {
  cin.tie(0); cout.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  long long ans = 0;
  for(int i = 1; i < N; i++) {
    int j = i;
    vector<int> p;
    for(int k = 2; k * k <= i; k++) {
      if(j % k == 0) {
        p.emplace_back(k);
        while(j % k == 0) {
          j /= k;
        }
      }
      if(j == 1) {
        break;
      }
    }
    if(j > 1) {
      p.emplace_back(j);
    }
    int sz = p.size();
    for(int bit = 1; bit < 1 << sz; bit++) {
      int S = 1;
      for(int j = 0; j < sz; j++) {
        if(bit >> j & 1) {
          S *= p[j];
        }
      }
      int add = N / S - i / S;
      if(__builtin_popcount(bit) % 2 == 0) {
        add *= -1;
      }
      //cout << i << ' ' << bit << ' ' << add << endl;
      ans += add;
    }
    if((int) p.size() > 0) {
      ans -= N / i - 1;
    }
    //cout<<i<<' '<<ans<<endl;
  }
  cout << ans << '\n';
  return 0;
}
0