結果
| 問題 |
No.2552 Not Coprime, Not Divisor
|
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2023-11-27 19:20:58 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 21 ms / 2,000 ms |
| コード長 | 689 bytes |
| コンパイル時間 | 771 ms |
| コンパイル使用メモリ | 41,668 KB |
| 実行使用メモリ | 7,168 KB |
| 最終ジャッジ日時 | 2024-09-26 12:33:40 |
| 合計ジャッジ時間 | 1,727 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 25 |
ソースコード
/* -*- 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;
}
tnakao0123