結果

問題 No.1514 Squared Matching
ユーザー 沙耶花沙耶花
提出日時 2021-05-21 21:54:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,611 ms / 4,000 ms
コード長 818 bytes
コンパイル時間 4,422 ms
コンパイル使用メモリ 253,640 KB
実行使用メモリ 405,948 KB
最終ジャッジ日時 2024-04-18 15:15:02
合計ジャッジ時間 29,448 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1,477 ms
405,636 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 18 ms
9,700 KB
testcase_07 AC 213 ms
80,388 KB
testcase_08 AC 1,309 ms
391,024 KB
testcase_09 AC 1,128 ms
342,432 KB
testcase_10 AC 1,224 ms
370,736 KB
testcase_11 AC 1,317 ms
385,996 KB
testcase_12 AC 1,355 ms
396,656 KB
testcase_13 AC 1,391 ms
401,768 KB
testcase_14 AC 1,490 ms
404,212 KB
testcase_15 AC 1,539 ms
404,948 KB
testcase_16 AC 1,593 ms
405,552 KB
testcase_17 AC 1,381 ms
405,664 KB
testcase_18 AC 1,369 ms
405,948 KB
testcase_19 AC 1,577 ms
405,828 KB
testcase_20 AC 1,573 ms
405,820 KB
testcase_21 AC 1,611 ms
405,824 KB
testcase_22 AC 265 ms
84,196 KB
testcase_23 AC 559 ms
164,856 KB
testcase_24 AC 883 ms
245,000 KB
testcase_25 AC 1,171 ms
325,420 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000001

int main(){
	
	int N;
	cin>>N;
	vector<int> p;
	vector<int> np(N+1,-1);
	
	for(int i=2;i<=N;i++){
		if(np[i]==-1){
			p.push_back(i);
			np[i] = i;
		}
		rep(j,p.size()){
			if(p[j]*i>N||p[j]>np[i]){
				break;
			}
			np[p[j]*i] = p[j];
		}
	}
	
	vector<int> cnt(N+1,0);
	cnt[1] = 1;
	
	for(int i=2;i<=N;i++){
		if(np[i]==i){
			cnt[i]++;
		}
		else{
			int T = np[i];
			if(np[i/T]%T==0){
				T = np[i/T]/T;
			}
			else{
				T = np[i/T]*T;
			}
			np[i] = T;
			cnt[T]++;
		}
	}
	
	long long ans = 0LL;
	rep(i,N+1){
		long long t = cnt[i];
		t *= t;
		ans += t;
	}
	
	cout<<ans<<endl;
			
	return 0;
}
0