結果

問題 No.1022 Power Equation
ユーザー petite_progpetite_prog
提出日時 2020-04-12 05:35:00
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 140 ms / 2,000 ms
コード長 2,825 bytes
コンパイル時間 1,594 ms
コンパイル使用メモリ 169,648 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-21 19:17:02
合計ジャッジ時間 3,260 ms
ジャッジサーバーID
(参考情報)
judge10 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

/*
   ∫ ∫ ∫
   ノヽ
  (_  )
 (_    )
(______ )
 ヽ(´・ω・)ノ 
   |  /
   UU
*/
#pragma region macro
#include <bits/stdc++.h>
typedef long long int64;
using namespace std;
using P = pair<int64, int64>;
typedef vector<int> vi;
const int MOD = (int)1e9 + 7;
const int64 INF = 1LL << 62;
const int inf = 1<<30;
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; }
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i,s,n) for (int i = s; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end() //コンテナじゃないと使えない!!
#define debug(x) cerr << #x << ": " << x << "\n";
#define mp make_pair
#define bn '\n'
template <typename T>
ostream& operator<<(ostream& os, const vector<T> &V){
    int N = V.size();
    REP(i,N){
        os << V[i];
        if (i!=N-1) os << " ";
    }
    os << "\n";
    return os;
}
template <typename T,typename S>
ostream& operator<<(ostream& os, pair<T,S> const&P){
    os << "(";
    os << P.first;
    os << " , ";
    os << P.second;
    os << ")";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, set<T> &S){
    auto it=S.begin();
    while(it!=S.end()){
        os << *it;
        os << " ";
        it++;
    }
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, deque<T> &q){
    for(auto it=q.begin();it<q.end();it++){
        os<<*it;
        os<<" ";
    }
    os<<endl;
    return os;
}
template <typename T,typename S>
ostream& operator<<(ostream& os, map<T,S> const&M){
    for(auto e:M){
        os<<e;
    }
    os<<endl;
    return os;
}
vector<pair<int,int>> dxdy = {mp(0,1),mp(1,0),mp(-1,0),mp(0,-1)};
#pragma endregion
//fixed<<setprecision(10)<<ans<<endl;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int n, int m){
    return n * (m / gcd(n, m));
}


//return m^k <= N
bool is_ok(int m, int k, int64 N){
    REP(i,k) N/=m;
    return N>0;
}

const int MAX_bd = 31; // floor(log2(10^9)) = 29
void solve(){
    int64 N;
    cin >> N;
    int64 ans=N*N-N; //1^a = 1^b
    ans += N*N; //a^b = a^b
    for(int b=1;b<MAX_bd;b++){
        for(int d=1;d<MAX_bd;d++){
            int k = max(b,d);
            if(gcd(b,d)!= 1 or k == 1) continue;
            
            int ok = 1, ng = 5e4; //N^(1/k)以下
            while(ng - ok > 1){
                int mid = (ok+ng)/2;
                if(is_ok(mid,k,N)) ok = mid;
                else ng = mid;
            }
            ans += (N/k)*(ok-1);
        }
    }
    cout << ans << bn;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    REP(i,N) solve();
}
0