結果

問題 No.6 使いものにならないハッシュ
ユーザー kou6839kou6839
提出日時 2014-11-09 01:26:34
言語 Java21
(openjdk 21)
結果
AC  
実行時間 183 ms / 5,000 ms
コード長 1,406 bytes
コンパイル時間 3,777 ms
コンパイル使用メモリ 75,844 KB
実行使用メモリ 58,832 KB
最終ジャッジ日時 2023-10-14 22:46:57
合計ジャッジ時間 10,491 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 119 ms
55,904 KB
testcase_01 AC 121 ms
55,804 KB
testcase_02 AC 180 ms
58,312 KB
testcase_03 AC 159 ms
56,104 KB
testcase_04 AC 160 ms
56,132 KB
testcase_05 AC 148 ms
55,876 KB
testcase_06 AC 167 ms
56,092 KB
testcase_07 AC 153 ms
56,268 KB
testcase_08 AC 154 ms
55,984 KB
testcase_09 AC 157 ms
55,868 KB
testcase_10 AC 118 ms
56,172 KB
testcase_11 AC 157 ms
56,376 KB
testcase_12 AC 174 ms
56,304 KB
testcase_13 AC 153 ms
56,004 KB
testcase_14 AC 155 ms
56,336 KB
testcase_15 AC 168 ms
55,772 KB
testcase_16 AC 152 ms
56,664 KB
testcase_17 AC 177 ms
56,092 KB
testcase_18 AC 183 ms
58,408 KB
testcase_19 AC 171 ms
55,812 KB
testcase_20 AC 170 ms
56,324 KB
testcase_21 AC 132 ms
55,672 KB
testcase_22 AC 173 ms
55,944 KB
testcase_23 AC 175 ms
55,808 KB
testcase_24 AC 173 ms
56,404 KB
testcase_25 AC 162 ms
56,120 KB
testcase_26 AC 175 ms
55,932 KB
testcase_27 AC 169 ms
56,920 KB
testcase_28 AC 154 ms
57,996 KB
testcase_29 AC 178 ms
58,832 KB
testcase_30 AC 176 ms
56,780 KB
testcase_31 AC 174 ms
55,740 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
 

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int K=sc.nextInt();
		int N = sc.nextInt();
		boolean[] nera = new boolean[N+1];
		Arrays.fill(nera, true);
		for(int i=2;i*i<=N;i++){
			if(nera[i]){
				for(int j=i*2;j<=N;j+=i){
					if(nera[j])nera[j]=false;
				}
			}
		}
		ArrayList<Integer> sosuu = new ArrayList<>();
		ArrayList<Integer> ha = new ArrayList<>();
		for(int i=K;i<=N;i++){
			if(i==1) continue;
			if(nera[i]){
				int temp=i;
				sosuu.add(i);
				while(temp>9){
					int temp2=temp;
					temp=0;
					while(temp2!=0){
						temp+=temp2%10;
						temp2=temp2/10;
					}
				}
				ha.add(temp);
			}
		}
		int t=0;
		int s=0;
		Queue<Integer> queue = new LinkedList<>();
		int ans=0;
		int ansmemo=0;
		int temp=0;
		int max=0;
		while(true){
			while(t<ha.size()){				
				if(queue.contains(ha.get(t))){
					if(t-s>=ans){
						ans=t-s;
						max=sosuu.get(s);
					}
					break;
				}
				if(t==ha.size()-1){
					int temp1=ha.get(t);
					queue.offer(temp1);
					if(t-s+1>=ans){
						max=sosuu.get(s);
					}
					System.out.println(max);
					return;
					
				}
				queue.offer(ha.get(t++));
			}
			while(true){
				int temp1=queue.poll();
				s++;
				if(temp1==ha.get(t)){
					break;
				}
				
			}
			
			
		}
		
	}
}	
0