結果

問題 No.2249 GCDistance
ユーザー Shell-WataruShell-Wataru
提出日時 2023-03-17 22:48:19
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 750 ms / 5,000 ms
コード長 2,038 bytes
コンパイル時間 1,968 ms
コンパイル使用メモリ 139,600 KB
実行使用メモリ 120,260 KB
最終ジャッジ日時 2023-10-18 15:50:28
合計ジャッジ時間 11,277 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 366 ms
120,260 KB
testcase_01 AC 736 ms
120,260 KB
testcase_02 AC 728 ms
120,260 KB
testcase_03 AC 726 ms
120,260 KB
testcase_04 AC 520 ms
120,260 KB
testcase_05 AC 739 ms
120,260 KB
testcase_06 AC 748 ms
120,260 KB
testcase_07 AC 750 ms
120,260 KB
testcase_08 AC 396 ms
120,260 KB
testcase_09 AC 728 ms
120,260 KB
testcase_10 AC 699 ms
120,260 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <limits>
#include <cmath>
#include <iomanip>
#include <functional>
#include <random>
#include <set>
#include <atcoder/string>
#include <unordered_map>
#include <climits>
#include <atcoder/lazysegtree>

using namespace std;
using ll = long long;
using namespace atcoder;

vector< int > euler_phi_table(int n) {
  vector< int > euler(n + 1);
  for(int i = 0; i <= n; i++) {
    euler[i] = i;
  }
  for(int i = 2; i <= n; i++) {
    if(euler[i] == i) {
      for(int j = i; j <= n; j += i) {
        euler[j] = euler[j] / i * (i - 1);
      }
    }
  }
  return euler;
}

int solve()
{
    ll N;
    cin >> N;
    vector<ll> A(N);
    vector<ll> B(N);
    set<pair<ll,pair<ll,ll>>> data;
    for(int i = 0;i < N;i++){
        cin >> A[i];
    }
    for(int i = 0;i < N;i++){
        cin >> B[i];
        if (A[i] > B[i]){
            swap(A[i],B[i]);
        }
        data.insert({B[i],{A[i],B[i]}});
    }
    ll ans = numeric_limits<ll>::max();
    while(true){
        ans = min(ans,data.rbegin()->first - data.begin()->first);
        auto p = *data.rbegin();
        if (p.first == p.second.first){
            break;
        }else if (p.first == (p.second.first + p.second.second)/2){
            data.insert({p.second.first,p.second});
        }else{
            data.insert({(p.second.first + p.second.second)/2,p.second});
        }
        data.erase(p);
    }
    cout << ans << endl;
    return 0;
}
int main()
{
    vector<int> phi_table = euler_phi_table(10000000);
    vector<ll> cumSum(10000001);
    for(int i = 1;i <= 10000000;i++){
        if (i == 1){
            cumSum[i] = cumSum[i-1] + phi_table[i]-1 + (i-phi_table[i])*2;
        }else{
            cumSum[i] = cumSum[i-1] + phi_table[i] + (i-1-phi_table[i])*2;
        }

    }
    ll T;
    cin >> T;
    while (T--)
    {
        ll N;
        cin >> N;
        cout << cumSum[N] << endl;
    }
    cout << flush;
    return 0;
}
0