結果

問題 No.6 使いものにならないハッシュ
ユーザー 37zigen37zigen
提出日時 2016-03-08 02:51:10
言語 Java21
(openjdk 21)
結果
AC  
実行時間 171 ms / 5,000 ms
コード長 1,483 bytes
コンパイル時間 2,176 ms
コンパイル使用メモリ 77,028 KB
実行使用メモリ 58,800 KB
最終ジャッジ日時 2023-10-14 22:58:53
合計ジャッジ時間 8,225 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 115 ms
56,268 KB
testcase_01 AC 119 ms
55,760 KB
testcase_02 AC 169 ms
58,388 KB
testcase_03 AC 130 ms
58,028 KB
testcase_04 AC 142 ms
58,608 KB
testcase_05 AC 139 ms
57,600 KB
testcase_06 AC 157 ms
57,772 KB
testcase_07 AC 159 ms
58,460 KB
testcase_08 AC 159 ms
58,196 KB
testcase_09 AC 159 ms
58,084 KB
testcase_10 AC 119 ms
55,580 KB
testcase_11 AC 134 ms
58,096 KB
testcase_12 AC 162 ms
58,136 KB
testcase_13 AC 158 ms
58,432 KB
testcase_14 AC 155 ms
58,328 KB
testcase_15 AC 156 ms
58,084 KB
testcase_16 AC 158 ms
58,292 KB
testcase_17 AC 162 ms
57,548 KB
testcase_18 AC 171 ms
58,740 KB
testcase_19 AC 160 ms
57,736 KB
testcase_20 AC 153 ms
58,336 KB
testcase_21 AC 129 ms
56,000 KB
testcase_22 AC 160 ms
58,576 KB
testcase_23 AC 159 ms
57,712 KB
testcase_24 AC 155 ms
57,652 KB
testcase_25 AC 156 ms
58,800 KB
testcase_26 AC 150 ms
58,232 KB
testcase_27 AC 154 ms
57,780 KB
testcase_28 AC 141 ms
58,280 KB
testcase_29 AC 165 ms
58,452 KB
testcase_30 AC 155 ms
58,212 KB
testcase_31 AC 156 ms
57,852 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) throws Exception {
		PrintWriter pw=new PrintWriter(System.out);
		Scanner sc=new Scanner(System.in);

		int k=sc.nextInt();
		int n=sc.nextInt();

		int s=k;
		int t=k;
		int len=0;

		ArrayList<Integer> isPrime=new ArrayList<>();
		isPrime=PrimeList(n);
		int i=0;
		while(i<isPrime.size()&&isPrime.get(i)<k){
			i++;
		}
		int memP=k;
		for(;i<=n;i++){
			boolean[] used=new boolean[10];
			for(int j=i;j<isPrime.size();j++){
				int h=hash(isPrime.get(j));
				if(used[h])break;
				used[h]=true;
				if(j-i+1>=len){
					len=j-i+1;
					memP=isPrime.get(i);
				}
			}
		}


		pw.println(memP);
		pw.close();
		sc.close();
	} 

	public static boolean[] isPrime(int max){//trueでPrime
		boolean[] p=new boolean[max+1];
		Arrays.fill(p, true);
		p[0]=false;
		p[1]=false;
		for(int i=2;i<=max;i++){
			if(p[i]==true){
				for(int j=2;j*i<=max;j++){
					p[j*i]=false;
				}
			}
		}
		return p;
	}

	public static int hash(int n){
		int sum=0;
		while(n>=1){
			sum+=n%10;
			n=(n-n%10)/10;
		}
		n=sum;
		if(n>=10){
			return hash(n);
		}else{
			return n;	
		}
	}
	public static ArrayList<Integer> PrimeList(int max){
		ArrayList<Integer> isPrime=new ArrayList<>();
		boolean[] p=new boolean[max+1];
		p=isPrime(max);
		for(int i=2;i<=max;i++){
			if(p[i]){
				isPrime.add(i);
			}
		}
		return isPrime;
	}

}
0