結果

問題 No.1262 グラフを作ろう!
ユーザー n_vipn_vip
提出日時 2020-10-16 22:43:42
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 285 ms / 3,000 ms
コード長 3,590 bytes
コンパイル時間 2,450 ms
コンパイル使用メモリ 136,240 KB
実行使用メモリ 27,572 KB
最終ジャッジ日時 2023-09-28 04:28:08
合計ジャッジ時間 24,158 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 170 ms
20,076 KB
testcase_01 AC 130 ms
16,932 KB
testcase_02 AC 203 ms
22,072 KB
testcase_03 AC 135 ms
17,660 KB
testcase_04 AC 150 ms
17,676 KB
testcase_05 AC 142 ms
17,732 KB
testcase_06 AC 173 ms
19,244 KB
testcase_07 AC 45 ms
10,616 KB
testcase_08 AC 202 ms
22,008 KB
testcase_09 AC 92 ms
14,568 KB
testcase_10 AC 104 ms
15,144 KB
testcase_11 AC 215 ms
22,800 KB
testcase_12 AC 155 ms
19,104 KB
testcase_13 AC 140 ms
18,192 KB
testcase_14 AC 108 ms
15,360 KB
testcase_15 AC 72 ms
13,220 KB
testcase_16 AC 190 ms
21,356 KB
testcase_17 AC 162 ms
19,328 KB
testcase_18 AC 219 ms
23,512 KB
testcase_19 AC 135 ms
16,748 KB
testcase_20 AC 204 ms
21,740 KB
testcase_21 AC 207 ms
22,876 KB
testcase_22 AC 120 ms
15,764 KB
testcase_23 AC 99 ms
14,756 KB
testcase_24 AC 200 ms
21,792 KB
testcase_25 AC 83 ms
13,096 KB
testcase_26 AC 102 ms
14,832 KB
testcase_27 AC 174 ms
19,708 KB
testcase_28 AC 154 ms
18,004 KB
testcase_29 AC 152 ms
18,188 KB
testcase_30 AC 110 ms
15,404 KB
testcase_31 AC 179 ms
20,892 KB
testcase_32 AC 141 ms
17,596 KB
testcase_33 AC 53 ms
11,240 KB
testcase_34 AC 214 ms
22,300 KB
testcase_35 AC 137 ms
17,996 KB
testcase_36 AC 54 ms
11,452 KB
testcase_37 AC 230 ms
24,068 KB
testcase_38 AC 164 ms
19,320 KB
testcase_39 AC 94 ms
14,516 KB
testcase_40 AC 106 ms
14,956 KB
testcase_41 AC 170 ms
19,468 KB
testcase_42 AC 213 ms
23,224 KB
testcase_43 AC 142 ms
17,580 KB
testcase_44 AC 138 ms
17,500 KB
testcase_45 AC 234 ms
23,544 KB
testcase_46 AC 200 ms
20,764 KB
testcase_47 AC 92 ms
14,696 KB
testcase_48 AC 199 ms
21,624 KB
testcase_49 AC 222 ms
23,520 KB
testcase_50 AC 216 ms
23,060 KB
testcase_51 AC 113 ms
15,952 KB
testcase_52 AC 185 ms
19,960 KB
testcase_53 AC 67 ms
12,056 KB
testcase_54 AC 165 ms
19,788 KB
testcase_55 AC 147 ms
18,140 KB
testcase_56 AC 166 ms
18,656 KB
testcase_57 AC 256 ms
25,884 KB
testcase_58 AC 144 ms
18,236 KB
testcase_59 AC 170 ms
19,228 KB
testcase_60 AC 240 ms
24,840 KB
testcase_61 AC 102 ms
15,064 KB
testcase_62 AC 202 ms
22,188 KB
testcase_63 AC 155 ms
19,320 KB
testcase_64 AC 135 ms
17,196 KB
testcase_65 AC 101 ms
14,492 KB
testcase_66 AC 113 ms
15,620 KB
testcase_67 AC 120 ms
16,028 KB
testcase_68 AC 191 ms
20,348 KB
testcase_69 AC 116 ms
15,664 KB
testcase_70 AC 231 ms
23,548 KB
testcase_71 AC 177 ms
20,300 KB
testcase_72 AC 234 ms
24,196 KB
testcase_73 AC 223 ms
23,596 KB
testcase_74 AC 186 ms
21,132 KB
testcase_75 AC 195 ms
21,404 KB
testcase_76 AC 171 ms
19,768 KB
testcase_77 AC 187 ms
21,240 KB
testcase_78 AC 197 ms
21,808 KB
testcase_79 AC 248 ms
25,256 KB
testcase_80 AC 232 ms
23,540 KB
testcase_81 AC 184 ms
20,876 KB
testcase_82 AC 210 ms
22,868 KB
testcase_83 AC 211 ms
22,724 KB
testcase_84 AC 174 ms
20,036 KB
testcase_85 AC 258 ms
26,048 KB
testcase_86 AC 196 ms
21,960 KB
testcase_87 AC 235 ms
24,260 KB
testcase_88 AC 180 ms
20,900 KB
testcase_89 AC 210 ms
21,956 KB
testcase_90 AC 285 ms
27,292 KB
testcase_91 AC 278 ms
27,572 KB
testcase_92 AC 277 ms
27,424 KB
testcase_93 AC 280 ms
27,484 KB
testcase_94 AC 279 ms
27,420 KB
testcase_95 AC 274 ms
27,304 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#include<random>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (int)(Y);++(X))
#define reps(X,S,Y) for (int (X) = (int)(S);(X) < (int)(Y);++(X))
#define rrep(X,Y) for (int (X) = (int)(Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (int)(Y)-1;(X) >= (int)(S);--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define Endl endl
#define NL <<"\n"
#define cauto const auto

using namespace std;
using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
//#undef NUIP
#ifdef NUIP
#include "benri.h"
#else
#define out(args...)
#endif
#ifdef __cpp_init_captures
template<typename T>vector<T> table(int n, T v){ return vector<T>(n, v);}
template <class... Args> auto table(int n, Args... args){auto val = table(args...); return vector<decltype(val)>(n, move(val));}
#endif
template<class A,class B> pair<A,B> operator+(const pair<A,B> &p,const pair<A,B> &q){ return {p.X+q.X,p.Y+q.Y};}
template<class A,class B,class C,class D> pair<A,B>& operator+=(pair<A,B> &p,const pair<C,D> &q){ p.X+=q.X; p.Y+=q.Y; return p;}
template<class A,class B> pair<A,B> operator-(const pair<A,B> &p,const pair<A,B> &q){ return {p.X-q.X,p.Y-q.Y};}
template<class A,class B,class C,class D> pair<A,B>& operator-=(pair<A,B> &p,const pair<C,D> &q){ p.X-=q.X; p.Y-=q.Y; return p;}
template<class A,class B> istream& operator>>(istream &is, pair<A,B> &p){ is>>p.X>>p.Y; return is;}
template<class T=ll> T read(){ T re; cin>>re; return move(re);}
template<class T=ll> T read(const T &dec){ T re; cin>>re; return re-dec;}
template<class T=ll> vector<T> readV(const int sz){ vector<T> re(sz); for(auto &x:re) x=read<T>(); return move(re);}
template<class T=ll> vector<T> readV(const int sz, const T &dec){ vector<T> re(sz); for(auto &x:re) x=read<T>(dec); return move(re);}
vv<int> readG(const int &n,const int &m){ vv<int> g(n); rep(_,m){ cauto a=read<int>(1),b=read<int>(1); g[a].pb(b); g[b].pb(a);} return move(g);}
vv<int> readG(const int &n){ return readG(n,n-1);}
const ll MOD=1e9+7; //998244353

vector<int> primes,prime;
class PRPRPR{
public:
  PRPRPR(int PRIME_MAX){
    prime.resize(PRIME_MAX);
    for(int i=2;i<PRIME_MAX;i++)if(!prime[i]){
	primes.pb(i);
	for(int j=i*2;j<PRIME_MAX;j+=i)
	  prime[j]=1;
      }
  }
} prprprpr(1123456);

int main(){
  ios_base::sync_with_stdio(false); cin.tie(0);
  cout<<fixed<<setprecision(0);
	cauto n=read();
	cauto m=read();
	cauto as=readV(m);

	vector<ll> tot(n+1,1);
	for(const ll p:primes){
		ll a=p-1;
		for(ll x=p;x<=n;x*=p){
			for(ll i=0;i<=n;i+=x) tot[i]*=a;
			a=p;
		}
	}
	
	vector<int> cnt(n+1);
	for(cauto a:as) cnt[a]++;
	ll re=0;
	reps(x,1,n+1)for(ll a=x;a<=n;a+=x){
		re+=cnt[a]*tot[a/x]*x;
		if(cnt[a]) out(a,x,cnt[a],tot[a/x],1);
	}
	re-=accumulate(all(as),0ll);
	cout<<re NL;
  return 0;
}
0