結果

問題 No.1514 Squared Matching
ユーザー racsosaberacsosabe
提出日時 2021-05-21 22:29:06
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,140 ms / 4,000 ms
コード長 778 bytes
コンパイル時間 1,719 ms
コンパイル使用メモリ 163,720 KB
実行使用メモリ 455,040 KB
最終ジャッジ日時 2024-04-18 16:03:23
合計ジャッジ時間 29,459 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 825 ms
259,584 KB
testcase_01 AC 1,140 ms
455,040 KB
testcase_02 AC 827 ms
259,584 KB
testcase_03 AC 829 ms
259,712 KB
testcase_04 AC 818 ms
259,712 KB
testcase_05 AC 822 ms
259,712 KB
testcase_06 AC 858 ms
262,528 KB
testcase_07 AC 874 ms
296,832 KB
testcase_08 AC 1,067 ms
447,616 KB
testcase_09 AC 1,046 ms
424,192 KB
testcase_10 AC 1,052 ms
437,888 KB
testcase_11 AC 1,073 ms
445,184 KB
testcase_12 AC 1,075 ms
450,432 KB
testcase_13 AC 1,082 ms
452,992 KB
testcase_14 AC 1,083 ms
454,016 KB
testcase_15 AC 1,078 ms
454,528 KB
testcase_16 AC 1,082 ms
454,912 KB
testcase_17 AC 1,070 ms
454,912 KB
testcase_18 AC 1,074 ms
454,912 KB
testcase_19 AC 1,077 ms
455,040 KB
testcase_20 AC 1,085 ms
454,912 KB
testcase_21 AC 1,076 ms
454,912 KB
testcase_22 AC 865 ms
298,752 KB
testcase_23 AC 922 ms
337,664 KB
testcase_24 AC 973 ms
376,832 KB
testcase_25 AC 1,021 ms
415,872 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace::std;

const int N = 50000000 + 5;

int n;
int cnt[N];
int primos[N];
int sqfree[N];
bool composite[N];

void init(){
	int len = 0;
	sqfree[1] = 1;
	for(int i = 2; i < N; i++){
		if(not composite[i]){
			primos[len++] = i;
			sqfree[i] = i;
		}
		for(int j = 0; j < len and i * primos[j] < N; j++){
			int p = primos[j];
			composite[i * p] = true;
			if(i % p == 0){
				sqfree[i * p] = sqfree[i] % p == 0 ? sqfree[i] / p : sqfree[i] * p;
				break;
			}
			else{
				sqfree[i * primos[j]] = sqfree[i] * primos[j];
			}
		}
	}
}

int main(){
	init();
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) cnt[sqfree[i]]++;
	long long ans = 0;
	for(int i = 1; i <= n; i++){
		ans += 1ll * cnt[i] * cnt[i];
	}
	printf("%lld\n", ans);
	return 0;
}
0