Submission #7636077


Source Code Expand

Copy
#include<bits/stdc++.h>
#define sz(v) ((int)(v).size())
using namespace std;
using lint = long long;
using pi = pair<int, int>;
const int MAXN = 1000005;
const int mod = 998244353;

lint ipow(lint x, lint p){
	lint ret = 1, piv = x;
	while(p){
		if(p & 1) ret = ret * piv % mod;
		piv = piv * piv % mod;
		p >>= 1;
	}
	return ret;
}

int n;
lint sum[MAXN];

int main(){
	cin >> n;
	lint tot = 0;
	for(int i=0; i<n; i++){
		int x; scanf("%d",&x);
		sum[x] += x;
		tot += x;
		if(sum[x] >= mod) sum[x] -= mod;
	}
	for(int i=1; i<MAXN; i++){
		for(int j=2*i; j<MAXN; j+=i){
			sum[i] += sum[j];
		}
		sum[i] %= mod;
		sum[i] = sum[i] * sum[i] % mod;
		// sum[i] = (i의 배수들의 합)^2
		// sum
	}
	for(int i=MAXN-1; i>=1; i--){
		for(int j=2*i; j<MAXN; j+=i){
			sum[i] += mod - sum[j]; 
			sum[i] %= mod;
		}
	}
	lint ret = 0;
	for(int i=1; i<MAXN; i++){
		ret += sum[i] * ipow(i, mod - 2);
		ret %= mod;
	}
	ret += mod - tot % mod;
	ret %= mod;
	ret *= ipow(2, mod - 2);
	ret %= mod;
	cout << ret << endl;
}

Submission Info

Submission Time
Task C - LCMs
User koosaga
Language C++14 (GCC 5.4.1)
Score 700
Code Size 1068 Byte
Status AC
Exec Time 265 ms
Memory 8192 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:26:24: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   int x; scanf("%d",&x);
                        ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 700 / 700
Status
AC × 3
AC × 21
Set Name Test Cases
Sample sample-01.txt, sample-02.txt, sample-03.txt
All 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, sample-01.txt, sample-02.txt, sample-03.txt
Case Name Status Exec Time Memory
01-01.txt AC 240 ms 8064 KB
01-02.txt AC 256 ms 8064 KB
01-03.txt AC 261 ms 8064 KB
01-04.txt AC 241 ms 8064 KB
01-05.txt AC 259 ms 8064 KB
01-06.txt AC 253 ms 8064 KB
01-07.txt AC 249 ms 8064 KB
01-08.txt AC 258 ms 8064 KB
01-09.txt AC 250 ms 8192 KB
01-10.txt AC 265 ms 8064 KB
01-11.txt AC 264 ms 8064 KB
01-12.txt AC 264 ms 8064 KB
01-13.txt AC 265 ms 8064 KB
01-14.txt AC 264 ms 8064 KB
01-15.txt AC 264 ms 8064 KB
01-16.txt AC 264 ms 8064 KB
01-17.txt AC 265 ms 8064 KB
01-18.txt AC 260 ms 8064 KB
sample-01.txt AC 240 ms 8064 KB
sample-02.txt AC 240 ms 8064 KB
sample-03.txt AC 239 ms 8064 KB