結果

問題 No.1262 グラフを作ろう!
ユーザー furafura
提出日時 2020-10-16 23:13:57
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,615 bytes
コンパイル時間 2,644 ms
コンパイル使用メモリ 211,816 KB
実行使用メモリ 30,520 KB
最終ジャッジ日時 2023-09-28 05:15:29
合計ジャッジ時間 62,961 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 702 ms
30,520 KB
testcase_01 AC 477 ms
13,912 KB
testcase_02 AC 738 ms
14,884 KB
testcase_03 AC 659 ms
15,276 KB
testcase_04 AC 76 ms
11,656 KB
testcase_05 AC 376 ms
13,256 KB
testcase_06 AC 52 ms
11,664 KB
testcase_07 AC 90 ms
11,972 KB
testcase_08 AC 494 ms
13,460 KB
testcase_09 AC 424 ms
14,112 KB
testcase_10 AC 347 ms
13,248 KB
testcase_11 AC 514 ms
13,692 KB
testcase_12 AC 669 ms
14,800 KB
testcase_13 AC 668 ms
15,092 KB
testcase_14 AC 303 ms
12,984 KB
testcase_15 AC 341 ms
13,716 KB
testcase_16 AC 531 ms
13,916 KB
testcase_17 AC 497 ms
13,660 KB
testcase_18 AC 780 ms
14,816 KB
testcase_19 AC 103 ms
11,828 KB
testcase_20 AC 267 ms
12,452 KB
testcase_21 AC 831 ms
15,276 KB
testcase_22 AC 53 ms
11,672 KB
testcase_23 AC 415 ms
13,792 KB
testcase_24 AC 524 ms
13,828 KB
testcase_25 AC 80 ms
11,652 KB
testcase_26 AC 148 ms
12,008 KB
testcase_27 AC 312 ms
12,708 KB
testcase_28 AC 274 ms
12,668 KB
testcase_29 AC 180 ms
12,140 KB
testcase_30 AC 232 ms
12,696 KB
testcase_31 AC 789 ms
15,332 KB
testcase_32 AC 438 ms
13,576 KB
testcase_33 AC 195 ms
12,636 KB
testcase_34 AC 388 ms
13,008 KB
testcase_35 AC 631 ms
14,792 KB
testcase_36 AC 221 ms
12,960 KB
testcase_37 AC 828 ms
15,076 KB
testcase_38 AC 420 ms
13,264 KB
testcase_39 AC 398 ms
13,732 KB
testcase_40 AC 360 ms
13,304 KB
testcase_41 AC 220 ms
12,248 KB
testcase_42 AC 677 ms
14,564 KB
testcase_43 AC 331 ms
13,008 KB
testcase_44 AC 401 ms
13,216 KB
testcase_45 AC 614 ms
14,044 KB
testcase_46 AC 167 ms
12,224 KB
testcase_47 AC 454 ms
14,456 KB
testcase_48 AC 574 ms
14,044 KB
testcase_49 AC 816 ms
15,192 KB
testcase_50 AC 679 ms
14,144 KB
testcase_51 AC 534 ms
14,328 KB
testcase_52 AC 210 ms
12,348 KB
testcase_53 AC 136 ms
12,104 KB
testcase_54 AC 793 ms
15,152 KB
testcase_55 AC 557 ms
14,072 KB
testcase_56 AC 228 ms
12,360 KB
testcase_57 AC 894 ms
15,372 KB
testcase_58 AC 707 ms
14,956 KB
testcase_59 AC 230 ms
12,208 KB
testcase_60 AC 861 ms
14,972 KB
testcase_61 AC 327 ms
12,888 KB
testcase_62 AC 757 ms
14,968 KB
testcase_63 AC 782 ms
15,240 KB
testcase_64 AC 512 ms
13,844 KB
testcase_65 AC 130 ms
12,072 KB
testcase_66 AC 346 ms
13,280 KB
testcase_67 AC 229 ms
12,492 KB
testcase_68 AC 144 ms
12,112 KB
testcase_69 AC 260 ms
12,608 KB
testcase_70 AC 626 ms
13,780 KB
testcase_71 AC 564 ms
13,952 KB
testcase_72 AC 763 ms
14,664 KB
testcase_73 AC 940 ms
15,312 KB
testcase_74 AC 623 ms
14,956 KB
testcase_75 AC 686 ms
14,544 KB
testcase_76 AC 543 ms
13,940 KB
testcase_77 AC 702 ms
14,760 KB
testcase_78 AC 650 ms
14,244 KB
testcase_79 AC 879 ms
15,116 KB
testcase_80 AC 588 ms
13,768 KB
testcase_81 AC 648 ms
14,664 KB
testcase_82 AC 871 ms
15,368 KB
testcase_83 AC 573 ms
13,556 KB
testcase_84 AC 555 ms
13,920 KB
testcase_85 AC 959 ms
15,344 KB
testcase_86 AC 730 ms
14,584 KB
testcase_87 AC 878 ms
15,100 KB
testcase_88 AC 646 ms
14,684 KB
testcase_89 AC 541 ms
13,496 KB
testcase_90 AC 248 ms
15,448 KB
testcase_91 AC 247 ms
15,624 KB
testcase_92 AC 247 ms
15,388 KB
testcase_93 AC 1,081 ms
15,404 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;
	}

	map<int,int> prime_factorize(int a)const{
		assert(a<=(int)lpf.size()-1);
		map<int,int> pf;
		for(;a>1;a/=lpf[a]) ++pf[lpf[a]];
		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 map<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