結果

問題 No.371 ぼく悪いプライムじゃないよ
ユーザー 37zigen37zigen
提出日時 2016-05-14 12:33:30
言語 Java19
(openjdk 21)
結果
AC  
実行時間 142 ms / 1,000 ms
コード長 2,126 bytes
コンパイル時間 2,650 ms
コンパイル使用メモリ 81,480 KB
実行使用メモリ 56,400 KB
最終ジャッジ日時 2023-08-29 00:59:05
合計ジャッジ時間 10,515 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 140 ms
55,792 KB
testcase_01 AC 136 ms
56,160 KB
testcase_02 AC 136 ms
55,884 KB
testcase_03 AC 135 ms
55,888 KB
testcase_04 AC 135 ms
55,952 KB
testcase_05 AC 136 ms
56,084 KB
testcase_06 AC 134 ms
56,240 KB
testcase_07 AC 134 ms
56,340 KB
testcase_08 AC 136 ms
55,732 KB
testcase_09 AC 136 ms
56,120 KB
testcase_10 AC 135 ms
55,532 KB
testcase_11 AC 135 ms
56,308 KB
testcase_12 AC 134 ms
54,180 KB
testcase_13 AC 137 ms
56,084 KB
testcase_14 AC 137 ms
55,864 KB
testcase_15 AC 134 ms
56,024 KB
testcase_16 AC 135 ms
55,540 KB
testcase_17 AC 135 ms
56,260 KB
testcase_18 AC 134 ms
56,104 KB
testcase_19 AC 135 ms
55,728 KB
testcase_20 AC 137 ms
56,088 KB
testcase_21 AC 136 ms
55,984 KB
testcase_22 AC 135 ms
56,316 KB
testcase_23 AC 142 ms
55,776 KB
testcase_24 AC 138 ms
56,324 KB
testcase_25 AC 140 ms
56,304 KB
testcase_26 AC 138 ms
55,776 KB
testcase_27 AC 137 ms
55,780 KB
testcase_28 AC 138 ms
56,224 KB
testcase_29 AC 139 ms
56,400 KB
testcase_30 AC 138 ms
56,032 KB
testcase_31 AC 138 ms
55,736 KB
testcase_32 AC 141 ms
55,984 KB
testcase_33 AC 140 ms
56,088 KB
testcase_34 AC 138 ms
56,220 KB
testcase_35 AC 137 ms
56,116 KB
testcase_36 AC 134 ms
55,892 KB
testcase_37 AC 136 ms
56,100 KB
testcase_38 AC 137 ms
55,912 KB
testcase_39 AC 134 ms
56,332 KB
testcase_40 AC 136 ms
55,800 KB
testcase_41 AC 135 ms
54,352 KB
testcase_42 AC 135 ms
56,284 KB
testcase_43 AC 135 ms
56,188 KB
testcase_44 AC 138 ms
56,228 KB
testcase_45 AC 136 ms
56,116 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
				new Main().solve();
	}
	void solve(){
		Scanner sc=new Scanner(System.in);
		int n=100000;
		Prime prime=new Prime();
		ArrayList<Integer> primeList=prime.primeList(n);
		
		long l=sc.nextLong();
		long h=sc.nextLong();
		
		for(int i=primeList.size()-1;i>=0;i--){
			long p=primeList.get(i);
			/*
			 * l<=p*j<=hを評価
			 * pは素数。
			 * jについての条件は
			 * p<=j。
			 * l/p<=j
			 * j<=h/p
			 */
			for(long j=h/p;j>=p&&p*j>=l;j--){
			
				long can=p*j;
				for(int k=0;k<=i;k++){
					if(k==i){
						System.out.println(can);
						return;
					}
					if(can%primeList.get(k)==0)break;
				}
			}
		}
		
	}
	void tr(Object...o){System.out.println(Arrays.deepToString(o));}
	class Prime{
		boolean[] isPrimeArray(int max){
			boolean[] isPrime=new boolean[max+1];
			Arrays.fill(isPrime, true);
			isPrime[0]=isPrime[1]=false;
			for(int i=2;i*i<=max;i++){
				if(isPrime[i]){
					for(int j=2;j*i<=max;j++){
						isPrime[j*i]=false;
					}
				}
			}
			return isPrime;
		}
		/*
		 * max以下の素数のリストを返す
		 */
		ArrayList<Integer> primeList(int max){
			boolean[] isPrime=isPrimeArray(max);
			ArrayList<Integer> primeList=new ArrayList<Integer>();
			for(int i=2;i<=max;i++){
				if(isPrime[i]){
					primeList.add(i);
				}
			}
			return primeList;
		}
		/*
		 * numをprimeListの素数をもとに素因数分解し、因数を
		 * ArrayList<Factor>の形で返す。
		 * primeListにはnumの平方根以下の素数が含まれていなければならない。
		 * 
		 */
		ArrayList<Factor> primeFactorF(ArrayList<Integer> primeList,long num){
			ArrayList<Factor> ret=new ArrayList<Factor>();
			for(int p:primeList){
				int exp=0;
				while(num%p==0){
					num/=p;
					exp++;
				}
				if(exp>0)ret.add(new Factor(p,exp));
			}
			if(num>1)ret.add(new Factor((int)num,1));
			return ret;
		}
	}
	class Factor{
		int base,exp;
		Factor(int base,int exp){
			this.base=base;
			this.exp=exp;
		}
	}
}
0