結果

問題 No.1022 Power Equation
ユーザー kotatsugamekotatsugame
提出日時 2020-04-15 12:11:38
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 14 ms / 2,000 ms
コード長 625 bytes
コンパイル時間 671 ms
コンパイル使用メモリ 69,928 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-09 18:36:28
合計ジャッジ時間 1,489 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,812 KB
testcase_01 AC 13 ms
6,944 KB
testcase_02 AC 14 ms
6,940 KB
testcase_03 AC 13 ms
6,940 KB
testcase_04 AC 14 ms
6,940 KB
testcase_05 AC 13 ms
6,944 KB
testcase_06 AC 13 ms
6,944 KB
testcase_07 AC 13 ms
6,940 KB
testcase_08 AC 14 ms
6,944 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:8:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    8 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int T;
long N;
main()
{
	cin>>T;
	for(;T--;)
	{
		cin>>N;
		long ans=0;
		int pre=1;
		for(int k=32;--k;)
		{
			long l=pre,r=N+1;
			while(r-l>1)
			{
				long m=(l+r)/2;
				long t=1;
				for(int j=0;j<k;j++)
				{
					t*=m;
					if(t>N)break;
				}
				if(t>N)r=m;
				else l=m;
			}
			int now=l;
			long tmp=0;
			for(int i=1;i<=k;i++)for(int j=1;j<=k;j++)
			{
				if(gcd(i,j)>1)continue;
				long t=N/max(i,j);
				tmp+=t;
			}
			ans+=tmp*(now-pre);
			pre=now;
		}
		cout<<ans+N*N<<endl;
	}
}
0