結果

問題 No.1233 割り切れない気持ち
ユーザー kotatsugamekotatsugame
提出日時 2020-09-18 21:59:06
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 75 ms / 3,153 ms
コード長 543 bytes
コンパイル時間 524 ms
コンパイル使用メモリ 64,652 KB
実行使用メモリ 7,376 KB
最終ジャッジ日時 2024-06-22 19:15:36
合計ジャッジ時間 3,766 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 39
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:8:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    8 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
using namespace std;
int N;
int cnt[2<<17];
int ex[2<<17];
long sum[2<<17];
const int MX=2e5;
main()
{
	cin>>N;
	for(int i=0;i<N;i++)
	{
		int A;cin>>A;
		cnt[A+1]++;
		ex[A]++;
		sum[A+1]+=A;
	}
	for(int i=1;i<=MX+1;i++)
	{
		cnt[i]+=cnt[i-1];
		sum[i]+=sum[i-1];
	}
	long ans=0;
	for(int i=1;i<=MX;i++)
	{
		int pre=0;
		int now=i;
		long c=0;
		while(pre<=MX)
		{
			ans+=ex[i]*((now<=MX?sum[now]:sum[MX+1])-sum[pre]-((now<=MX?cnt[now]:cnt[MX+1])-cnt[pre])*c*i);
			pre=now;
			now+=i;
			c++;
		}
	}
	cout<<ans<<endl;
}
0