結果

問題 No.1233 割り切れない気持ち
コンテスト
ユーザー 37zigen
提出日時 2020-09-21 06:02:35
言語 Java
(openjdk 25.0.2)
コンパイル:
javac -encoding UTF8 _filename_
実行:
java -ea -Xmx700m -Xss256M -DONLINE_JUDGE=true _class_
結果
AC  
実行時間 501 ms / 3,153 ms
コード長 722 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,675 ms
コンパイル使用メモリ 82,796 KB
実行使用メモリ 63,244 KB
最終ジャッジ日時 2026-03-10 14:06:06
合計ジャッジ時間 17,502 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 39
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;
import java.util.Stack;

class Main {
	public static void main(String[] $) {
		new Main().run();
	}
	
	void run() {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int[] A=new int[(int)2e5+1];
		int[] s=new int[(int)2e5+1];
		long ans=0;
		for (int i=0;i<N;++i) {
			int a=sc.nextInt();
			s[a]++;
			ans+=1L*a*N;
			A[a]++;
		}
		for (int i=s.length-2;i>=0;--i) {
			s[i]+=s[i+1];
		}
		for (int i=0;i<=(int)2e5;++i) {
			if (A[i]==0) continue;
			for (int a=i;a<s.length;a+=i) {
				ans-=1L*s[a]*i*A[i];
			}
		}
		System.out.println(ans);
		
	}
	
	void tr(Object...objects) {System.out.println(Arrays.deepToString(objects));}
}
0