結果

問題 No.2249 GCDistance
ユーザー pointNpointN
提出日時 2023-03-17 22:24:45
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,219 ms / 5,000 ms
コード長 1,698 bytes
コンパイル時間 1,583 ms
コンパイル使用メモリ 127,520 KB
最終ジャッジ日時 2025-02-11 13:32:39
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 10
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
//#include <atcoder/all>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
ll euler_phi(ll n) {
ll ret = n;
for(ll i = 2; i * i <= n; i++) {
if(n % i == 0) {
ret -= ret / i;
while(n % i == 0) n /= i;
}
}
if(n > 1) ret -= ret / n;
return ret;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int e7 = 10000000;
vector<int> prime(e7+1, 0);
prime[0] = prime[1] = 1;
for(int i=2; i <= e7; i++){
if(prime[i]==0){
for(int j=i*2; j <= e7; j+=i){
if(prime[j]==0) prime[j]=i;
}
prime[i]=i;
}
}
vector<ll> ps(e7+2,0);
for(int i=2;i<=e7;i++){
int now = i;
ll ret = now;
while(now!=1){
int d = prime[now];
ret -= ret / d;
while(now%d==0) now/=d;
}
if(now>1) ret -= ret/now;
ps[i+1] = ps[i]+ret;
}
int T; cin >> T;
while(T--){
ll N; cin >> N;
ll ans = N*(N-1);
ans -= ps[N+1];
cout << ans << '\n';
}
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0