結果

問題 No.2249 GCDistance
ユーザー ransewhaleransewhale
提出日時 2023-03-18 01:22:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,513 ms / 5,000 ms
コード長 843 bytes
コンパイル時間 765 ms
コンパイル使用メモリ 77,264 KB
実行使用メモリ 169,852 KB
最終ジャッジ日時 2023-10-18 16:49:02
合計ジャッジ時間 19,416 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,126 ms
169,852 KB
testcase_01 AC 1,496 ms
169,852 KB
testcase_02 AC 1,497 ms
169,852 KB
testcase_03 AC 1,511 ms
169,852 KB
testcase_04 AC 1,266 ms
169,852 KB
testcase_05 AC 1,513 ms
169,852 KB
testcase_06 AC 1,450 ms
169,852 KB
testcase_07 AC 1,454 ms
169,852 KB
testcase_08 AC 1,160 ms
169,852 KB
testcase_09 AC 1,506 ms
169,852 KB
testcase_10 AC 1,425 ms
169,852 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>

#pragma GCC optimize("O2")

using ll = long long int;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

bool f[10010010];
ll memo[10010010],ans[10010010];

int main(void){
	int t;
	ll i,j,n=10000000;
	for(i=2; i<=n; ++i){
		memo[i] = i;
	}
	for(i=2; i<=n; ++i){
		if(!f[i]){
			for(j=i; j<=n; j+=i){
				memo[j] /= i;
				memo[j] *= (i-1);
				f[j] = true;
			}
		}
		ans[i] = ans[i-1] + (i-memo[i]-1)*2+memo[i]; 
	}
	std::cin >> t;
	while(t--){
		std::cin >> n;
		std::cout << ans[n] << std::endl;
	}
	return 0;
}
0