結果
| 問題 | 
                            No.1022 Power Equation
                             | 
                    
| コンテスト | |
| ユーザー | 
                             catupper
                         | 
                    
| 提出日時 | 2020-04-10 22:37:58 | 
| 言語 | C++11(廃止可能性あり)  (gcc 13.3.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,303 bytes | 
| コンパイル時間 | 1,545 ms | 
| コンパイル使用メモリ | 72,060 KB | 
| 実行使用メモリ | 5,376 KB | 
| 最終ジャッジ日時 | 2024-09-15 21:15:31 | 
| 合計ジャッジ時間 | 2,103 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 | 
| other | AC * 4 WA * 4 | 
ソースコード
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cassert>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;
Int gcd(int x, int y){
    if(x == 0)return y;
    return gcd(y % x, x);
}
int totient(int x){
    Int ans = 0;
    for(int i = 1;i <= x;i++){
        ans += gcd(i, x) == 1;
    }
    return ans;
}
Int larger(Int a, Int b,Int x){
    Int tmp = 1;
    for(int i = 5;i >= 0;i--){
        tmp *= tmp;
        if(tmp >= x)return true;
        if((b & (1 << i)) == 0)continue;
        tmp *= a;
        if(tmp >= x)return true;
    }
    return false;
}
void solve(){
    Int n;
    cin >> n;
    Int ans = n*n * 2 - n;
    for(Int q = 2;q < 40;q++){
        Int bottom = 0, top = n;
        while(top - bottom > 1){
            Int mid = (top + bottom) / 2;
            if(larger(mid, q, n))top = mid;
            else bottom = mid;
        }
        if(bottom == 1)break;
        ans += (n / q) * totient(q) * (bottom -1)* 2;
    }
    cout << ans << endl;
}
int main(){
    int t;
    cin >> t;
    while(t--)solve();
    return 0;
}
            
            
            
        
            
catupper