結果

問題 No.1022 Power Equation
ユーザー carrot46carrot46
提出日時 2020-04-10 22:05:23
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 26 ms / 2,000 ms
コード長 1,329 bytes
コンパイル時間 1,449 ms
コンパイル使用メモリ 166,244 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-14 00:37:12
合計ジャッジ時間 2,197 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B;
string S;
const ll MOD = 998244353;
//const ll MOD = (1e+9) + 7;
const ll INF = 1LL<<60;
typedef pair<ll, ll> P;

ll extgcd(ll a, ll b, ll &x, ll &y){
    ll d = a;
    if(b != 0){
        d = extgcd(b, a%b, y, x);
        y -= (a/b) * x;
    }else{
        x=1;
        y=0;
    }
    return d;
}


ll fastpow(ll a, ll pw) {
	ll res = 1;
	while (pw) {
	    if(a > 1e+9) return 2e+9;
		if (pw & 1) res = res * a;
		a = a * a;
		pw >>= 1;
	}
	return res;
}

ll solve(ll n){
    ll res = n * n + (n - 1) * n;
    reps(b, 2, min(31LL, n + 1)){
        reps(d, 1, b){
            ll x, y;
            if(extgcd(b, d, x, y) == 1) {
                reps(tn, 2, 32000) {
                    ll c = fastpow(tn, b);
                    if(c > n) break;
                    res += 2 * (n / b);
                }
            }
        }
    }
    return res;
}

int main() {
    cin>>Q;
    rep(i,Q){
        cin>>N;
        cout<<solve(N)<<endl;
    }
}
0