結果

問題 No.1022 Power Equation
ユーザー catuppercatupper
提出日時 2020-04-10 22:42:38
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,301 bytes
コンパイル時間 801 ms
コンパイル使用メモリ 72,568 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-10-14 01:48:30
合計ジャッジ時間 1,538 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,368 KB
testcase_01 AC 2 ms
4,372 KB
testcase_02 AC 2 ms
4,368 KB
testcase_03 AC 2 ms
4,368 KB
testcase_04 AC 2 ms
4,368 KB
testcase_05 AC 2 ms
4,368 KB
testcase_06 AC 3 ms
4,372 KB
testcase_07 AC 3 ms
4,372 KB
testcase_08 AC 2 ms
4,368 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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