結果

問題 No.917 Make One With GCD
ユーザー 37zigen37zigen
提出日時 2020-03-09 17:23:28
言語 Java19
(openjdk 21)
結果
AC  
実行時間 163 ms / 2,000 ms
コード長 951 bytes
コンパイル時間 2,398 ms
コンパイル使用メモリ 75,548 KB
実行使用メモリ 57,172 KB
最終ジャッジ日時 2023-09-06 16:48:22
合計ジャッジ時間 8,113 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 128 ms
55,896 KB
testcase_01 AC 116 ms
55,960 KB
testcase_02 AC 117 ms
55,788 KB
testcase_03 AC 118 ms
56,044 KB
testcase_04 AC 118 ms
56,060 KB
testcase_05 AC 130 ms
55,724 KB
testcase_06 AC 163 ms
57,172 KB
testcase_07 AC 159 ms
56,832 KB
testcase_08 AC 119 ms
55,968 KB
testcase_09 AC 132 ms
56,128 KB
testcase_10 AC 131 ms
56,624 KB
testcase_11 AC 131 ms
56,100 KB
testcase_12 AC 131 ms
56,072 KB
testcase_13 AC 132 ms
55,996 KB
testcase_14 AC 131 ms
55,740 KB
testcase_15 AC 128 ms
56,236 KB
testcase_16 AC 126 ms
55,968 KB
testcase_17 AC 119 ms
55,796 KB
testcase_18 AC 128 ms
56,764 KB
testcase_19 AC 119 ms
55,728 KB
testcase_20 AC 120 ms
55,496 KB
testcase_21 AC 122 ms
54,548 KB
testcase_22 AC 122 ms
55,860 KB
testcase_23 AC 131 ms
55,788 KB
testcase_24 AC 127 ms
55,500 KB
testcase_25 AC 124 ms
55,900 KB
testcase_26 AC 119 ms
55,784 KB
testcase_27 AC 118 ms
56,072 KB
testcase_28 AC 118 ms
55,496 KB
testcase_29 AC 117 ms
55,792 KB
testcase_30 AC 118 ms
55,996 KB
testcase_31 AC 117 ms
55,756 KB
testcase_32 AC 117 ms
55,964 KB
testcase_33 AC 119 ms
55,732 KB
testcase_34 AC 117 ms
56,144 KB
testcase_35 AC 119 ms
56,320 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		new Main().run();
	}
	
	int gcd(int a,int b) {
		return a==0?b:gcd(b%a,a);
	}
	
	void run() {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int[] a=new int[n];
		for(int i=0;i<n;++i)a[i]=sc.nextInt();
		long ng=0;
		for(int i=0;i<n;++i) {
			if(a[i]==1)continue;
			ArrayList<Integer> divs=new ArrayList<>();
			for(int div=2;div*div<=a[i];++div) {
				int sz=0;
				while(a[i]%div==0) {
					a[i]/=div;
					++sz;
				}
				if(sz>0) {
					divs.add(div);
				}
			}
			if(a[i]>1)divs.add(a[i]);
			long add=0;
			for(int s=1;s<1<<divs.size();++s) {
				long g=1;
				int sz=0;
				for(int shift=0;shift<divs.size();++shift)if((s&(1<<shift))>0)g*=divs.get(shift);
				for(int j=i+1;j<n;++j)if(a[j]%g==0)++sz;
				add+=(1L<<sz)*(Integer.bitCount(s)%2==1?1:-1);
			}
			ng+=add;
		}
		System.out.println((1L<<n)-1-ng);
	}
}


0