結果

問題 No.2249 GCDistance
ユーザー publfl2publfl2
提出日時 2023-03-17 22:01:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,725 ms / 5,000 ms
コード長 668 bytes
コンパイル時間 422 ms
コンパイル使用メモリ 32,156 KB
実行使用メモリ 159,540 KB
最終ジャッジ日時 2023-10-18 14:45:12
合計ジャッジ時間 22,718 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,543 ms
159,540 KB
testcase_01 AC 1,663 ms
159,540 KB
testcase_02 AC 1,662 ms
159,540 KB
testcase_03 AC 1,652 ms
159,540 KB
testcase_04 AC 1,614 ms
159,540 KB
testcase_05 AC 1,704 ms
159,540 KB
testcase_06 AC 1,722 ms
159,540 KB
testcase_07 AC 1,688 ms
159,540 KB
testcase_08 AC 1,624 ms
159,540 KB
testcase_09 AC 1,725 ms
159,540 KB
testcase_10 AC 1,707 ms
159,540 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:3:5: warning: built-in function 'free' declared as non-function [-Wbuiltin-declaration-mismatch]
    3 | int free[10000010],prime[10000010];
      |     ^~~~

ソースコード

diff #

#include <stdio.h>

int free[10000010],prime[10000010];
long long int count[10000010];
int main()
{
	for(int i=2;i<=10000000;i++) if(prime[i]==0) for(int j=i;j<=10000000;j+=i) prime[j]++;
	for(int i=2;i<=10000;i++) for(int j=i*i;j<=10000000;j+=i*i) free[j] = 1;
	for(int i=1;i<=10000000;i++)
	{
		if(free[i]==0)
		{
			int C = 0;
			for(int j=i;j<=10000000;j+=i)
			{
				C++;
				if(prime[i]%2==0) count[j] += C;
				else count[j] -= C;
			}
		}
	}
	count[1]--;
	for(int i=1;i<=10000000;i++) count[i] += count[i-1];
	
	int T;
	scanf("%d",&T);
	while(T--)
	{
		long long int a;
		scanf("%lld",&a);
		long long int ans = a*(a-1);
		printf("%lld\n",ans - count[a]);
	}
}
0