結果

問題 No.1262 グラフを作ろう!
ユーザー furafura
提出日時 2020-10-16 23:18:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,753 bytes
コンパイル時間 3,164 ms
コンパイル使用メモリ 208,484 KB
実行使用メモリ 24,172 KB
最終ジャッジ日時 2023-09-28 05:19:14
合計ジャッジ時間 49,412 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 516 ms
14,904 KB
testcase_01 AC 350 ms
13,856 KB
testcase_02 AC 526 ms
14,892 KB
testcase_03 AC 521 ms
15,200 KB
testcase_04 AC 59 ms
11,804 KB
testcase_05 AC 282 ms
13,256 KB
testcase_06 AC 43 ms
11,608 KB
testcase_07 AC 74 ms
12,116 KB
testcase_08 AC 365 ms
13,596 KB
testcase_09 AC 351 ms
14,152 KB
testcase_10 AC 260 ms
13,276 KB
testcase_11 AC 379 ms
13,636 KB
testcase_12 AC 492 ms
14,796 KB
testcase_13 AC 536 ms
15,188 KB
testcase_14 AC 242 ms
12,980 KB
testcase_15 AC 289 ms
13,664 KB
testcase_16 AC 397 ms
13,788 KB
testcase_17 AC 377 ms
13,732 KB
testcase_18 AC 583 ms
14,860 KB
testcase_19 AC 76 ms
11,844 KB
testcase_20 AC 198 ms
12,612 KB
testcase_21 AC 597 ms
15,272 KB
testcase_22 AC 41 ms
11,608 KB
testcase_23 AC 332 ms
13,832 KB
testcase_24 AC 379 ms
13,780 KB
testcase_25 AC 63 ms
11,844 KB
testcase_26 AC 112 ms
12,120 KB
testcase_27 AC 233 ms
12,860 KB
testcase_28 AC 197 ms
12,716 KB
testcase_29 AC 132 ms
12,284 KB
testcase_30 AC 181 ms
12,584 KB
testcase_31 AC 576 ms
15,416 KB
testcase_32 AC 324 ms
13,576 KB
testcase_33 AC 166 ms
12,784 KB
testcase_34 AC 288 ms
13,120 KB
testcase_35 AC 499 ms
14,840 KB
testcase_36 AC 187 ms
12,960 KB
testcase_37 AC 604 ms
15,184 KB
testcase_38 AC 311 ms
13,340 KB
testcase_39 AC 319 ms
13,772 KB
testcase_40 AC 275 ms
13,268 KB
testcase_41 AC 157 ms
12,384 KB
testcase_42 AC 503 ms
14,420 KB
testcase_43 AC 240 ms
12,912 KB
testcase_44 AC 295 ms
13,376 KB
testcase_45 AC 446 ms
14,324 KB
testcase_46 AC 119 ms
12,032 KB
testcase_47 AC 382 ms
14,540 KB
testcase_48 AC 422 ms
14,092 KB
testcase_49 AC 576 ms
15,232 KB
testcase_50 AC 467 ms
14,392 KB
testcase_51 AC 434 ms
14,320 KB
testcase_52 AC 154 ms
12,288 KB
testcase_53 AC 107 ms
12,064 KB
testcase_54 AC 576 ms
15,192 KB
testcase_55 AC 403 ms
14,032 KB
testcase_56 AC 162 ms
12,380 KB
testcase_57 AC 628 ms
15,360 KB
testcase_58 AC 499 ms
14,948 KB
testcase_59 AC 152 ms
12,420 KB
testcase_60 AC 581 ms
15,120 KB
testcase_61 AC 238 ms
12,928 KB
testcase_62 AC 540 ms
14,972 KB
testcase_63 AC 583 ms
15,568 KB
testcase_64 AC 360 ms
13,816 KB
testcase_65 AC 94 ms
12,216 KB
testcase_66 AC 245 ms
13,096 KB
testcase_67 AC 162 ms
12,532 KB
testcase_68 AC 99 ms
12,084 KB
testcase_69 AC 184 ms
12,552 KB
testcase_70 AC 418 ms
14,144 KB
testcase_71 AC 390 ms
13,828 KB
testcase_72 AC 513 ms
14,376 KB
testcase_73 AC 636 ms
15,444 KB
testcase_74 AC 528 ms
15,060 KB
testcase_75 AC 461 ms
14,528 KB
testcase_76 AC 367 ms
13,744 KB
testcase_77 AC 516 ms
14,768 KB
testcase_78 AC 439 ms
14,248 KB
testcase_79 AC 604 ms
14,960 KB
testcase_80 AC 400 ms
13,724 KB
testcase_81 AC 503 ms
14,768 KB
testcase_82 AC 610 ms
15,600 KB
testcase_83 AC 396 ms
13,764 KB
testcase_84 AC 375 ms
13,924 KB
testcase_85 AC 642 ms
15,316 KB
testcase_86 AC 507 ms
14,540 KB
testcase_87 AC 574 ms
14,956 KB
testcase_88 AC 504 ms
14,672 KB
testcase_89 AC 359 ms
13,552 KB
testcase_90 AC 207 ms
15,352 KB
testcase_91 AC 210 ms
15,356 KB
testcase_92 AC 208 ms
15,484 KB
testcase_93 AC 1,035 ms
15,408 KB
testcase_94 TLE -
testcase_95 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;
using lint=long long;

class linear_sieve{
	vector<int> lpf,p;
public:
	linear_sieve(int n):lpf(n+1){
		for(int i=2;i<=n;i++){
			if(lpf[i]==0){
				lpf[i]=i;
				p.emplace_back(i);
			}
			for(int j=0;j<p.size()&&p[j]<=lpf[i]&&i*p[j]<=n;j++) lpf[i*p[j]]=p[j];
		}
	}

	const vector<int>& primes()const{ return p; }

	bool is_prime(int a)const{
		assert(a<=(int)lpf.size()-1);
		return a>0 && lpf[a]==a;
	}

	vector<pair<int,int>> prime_factorize(int a)const{
		assert(a<=(int)lpf.size()-1);
		vector<pair<int,int>> pf;
		for(;a>1;a/=lpf[a]){
			if(pf.empty() || pf.back().first!=lpf[a]){
				pf.emplace_back(lpf[a],1);
			}
			else{
				pf.back().second++;
			}
		}
		return pf;
	}

	int number_of_divisors(int a)const{
		assert(a<=(int)lpf.size()-1);
		int res=1,cnt=0,pre=-1;
		for(;a>1;a/=lpf[a]){
			if(pre==-1 || pre==lpf[a]){
				cnt++;
			}
			else{
				res*=cnt+1;
				cnt=1;
			}
			pre=lpf[a];
		}
		return res*(cnt+1);
	}
};

template<class T>
vector<T> divisors(const vector<pair<T,int>>& pf){
	vector<T> res={T(1)};
	for(const auto& q:pf){
		int m=res.size();
		T pp=1;
		rep(i,q.second){
			pp*=q.first;
			rep(i,m) res.emplace_back(res[i]*pp);
		}
	}
	sort(res.begin(),res.end());
	return res;
}

int phi[1000001];
void build_phi(){
	rep(i,1000001) phi[i]=i;
	for(int i=2;i<=1000000;i++) if(phi[i]==i) {
		for(int j=i;j<=1000000;j+=i) phi[j]=phi[j]/i*(i-1);
	}
}

int main(){
	build_phi();

	int n,m; scanf("%d%d",&n,&m);
	vector<int> a(m);
	rep(i,m) scanf("%d",&a[i]);

	lint ans=0;
	linear_sieve LS(1e6);
	rep(i,m){
		for(int d:divisors(LS.prime_factorize(a[i]))){
			ans+=lint((a[i]-1)%d)*phi[a[i]/d];
		}
	}
	printf("%lld\n",ans);

	return 0;
}
0