結果

問題 No.2552 Not Coprime, Not Divisor
ユーザー tnakao0123tnakao0123
提出日時 2023-11-27 19:20:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 21 ms / 2,000 ms
コード長 689 bytes
コンパイル時間 379 ms
コンパイル使用メモリ 41,792 KB
実行使用メモリ 7,004 KB
最終ジャッジ日時 2023-11-27 19:21:00
合計ジャッジ時間 1,894 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
6,676 KB
testcase_01 AC 16 ms
6,676 KB
testcase_02 AC 8 ms
6,676 KB
testcase_03 AC 16 ms
6,676 KB
testcase_04 AC 16 ms
6,676 KB
testcase_05 AC 5 ms
6,676 KB
testcase_06 AC 17 ms
6,676 KB
testcase_07 AC 19 ms
6,748 KB
testcase_08 AC 13 ms
6,676 KB
testcase_09 AC 21 ms
7,004 KB
testcase_10 AC 8 ms
6,676 KB
testcase_11 AC 12 ms
6,676 KB
testcase_12 AC 20 ms
6,748 KB
testcase_13 AC 9 ms
6,676 KB
testcase_14 AC 7 ms
6,676 KB
testcase_15 AC 1 ms
6,676 KB
testcase_16 AC 2 ms
6,676 KB
testcase_17 AC 6 ms
6,676 KB
testcase_18 AC 1 ms
6,676 KB
testcase_19 AC 2 ms
6,676 KB
testcase_20 AC 1 ms
6,676 KB
testcase_21 AC 1 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 #

/* -*- coding: utf-8 -*-
 *
 * 2552.cc:  No.2552 Not Coprime, Not Divisor - yukicoder
 */

#include<cstdio>
#include<algorithm>
 
using namespace std;

/* constant */

const int MAX_N = 1000000;

/* typedef */

typedef long long ll;

/* global variables */

int phis[MAX_N + 1];

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d", &n);

  for (int i = 1; i <= n; i++) phis[i] = i;

  for (int p = 2; p <= n; p++)
    if (phis[p] == p) {
      phis[p]--;
      for (int i = 2; i * p <= n; i++)
	phis[i * p] -= phis[i * p] / p;
    }
  
  ll sum = (ll)n * (n - 1) / 2;
  for (int x = 2; x <= n; x++)
    sum -= phis[x] + (n / x - 1);

  printf("%lld\n", sum);

  return 0;
}
0