結果

問題 No.2249 GCDistance
ユーザー pointNpointN
提出日時 2023-03-17 22:24:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,421 ms / 5,000 ms
コード長 1,698 bytes
コンパイル時間 1,292 ms
コンパイル使用メモリ 132,248 KB
実行使用メモリ 120,396 KB
最終ジャッジ日時 2023-10-18 15:21:00
合計ジャッジ時間 19,765 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,318 ms
120,396 KB
testcase_01 AC 1,392 ms
120,396 KB
testcase_02 AC 1,421 ms
120,396 KB
testcase_03 AC 1,389 ms
120,396 KB
testcase_04 AC 1,367 ms
120,396 KB
testcase_05 AC 1,407 ms
120,396 KB
testcase_06 AC 1,400 ms
120,396 KB
testcase_07 AC 1,392 ms
120,396 KB
testcase_08 AC 1,353 ms
120,396 KB
testcase_09 AC 1,387 ms
120,396 KB
testcase_10 AC 1,381 ms
120,396 KB
権限があれば一括ダウンロードができます

ソースコード

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;
}
0