結果

問題 No.1022 Power Equation
ユーザー chocoruskchocorusk
提出日時 2020-02-25 12:49:55
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 652 bytes
コンパイル時間 640 ms
コンパイル使用メモリ 64,564 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-20 19:33:07
合計ジャッジ時間 1,226 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
using namespace std;
typedef long long ll;
int gcd(int a, int b){
	if(b==0) return a;
	return gcd(b, a%b);
}
ll cnt[30], a[30];
ll root(ll n, int k){
	if(k==1) return n;
	ll l=1, r=32000;
	while(r-l>1){
		ll x=n, mid=(l+r)/2;
		for(int i=0; i<k; i++) x/=mid;
		if(x) l=mid;
		else r=mid;
	}
	return l;
}
ll solve(ll n){
	for(int i=1; i<30; i++) a[i]=root(n, i);
	ll ret=n*n;
	for(int i=1; i<30; i++) ret+=n/i*(a[i]-1)*cnt[i];
	return ret;
}
int main()
{
    int t;
	cin>>t;
	for(int i=1; i<30; i++) for(int j=1; j<30; j++) if(gcd(i, j)==1) cnt[max(i, j)]++;
	while(t--){
		ll n;
		cin>>n;
		cout<<solve(n)<<endl;
	}
    return 0;
}
0