結果
問題 | No.6 使いものにならないハッシュ |
ユーザー | core123 |
提出日時 | 2019-04-17 17:26:05 |
言語 | Java21 (openjdk 21) |
結果 |
WA
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 1,877 bytes |
コンパイル時間 | 2,927 ms |
コンパイル使用メモリ | 76,440 KB |
実行使用メモリ | 60,056 KB |
最終ジャッジ日時 | 2023-10-14 23:16:59 |
合計ジャッジ時間 | 10,455 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge14 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 120 ms
55,772 KB |
testcase_01 | AC | 123 ms
56,376 KB |
testcase_02 | AC | 236 ms
59,496 KB |
testcase_03 | AC | 165 ms
59,848 KB |
testcase_04 | AC | 183 ms
59,856 KB |
testcase_05 | AC | 194 ms
59,816 KB |
testcase_06 | AC | 212 ms
59,784 KB |
testcase_07 | AC | 193 ms
59,320 KB |
testcase_08 | AC | 206 ms
59,760 KB |
testcase_09 | AC | 181 ms
58,808 KB |
testcase_10 | WA | - |
testcase_11 | AC | 180 ms
59,880 KB |
testcase_12 | AC | 218 ms
59,436 KB |
testcase_13 | AC | 171 ms
58,204 KB |
testcase_14 | AC | 175 ms
58,432 KB |
testcase_15 | AC | 211 ms
59,612 KB |
testcase_16 | AC | 191 ms
59,340 KB |
testcase_17 | AC | 221 ms
59,568 KB |
testcase_18 | AC | 216 ms
59,708 KB |
testcase_19 | AC | 205 ms
59,420 KB |
testcase_20 | AC | 202 ms
59,784 KB |
testcase_21 | AC | 160 ms
59,784 KB |
testcase_22 | AC | 211 ms
59,848 KB |
testcase_23 | AC | 212 ms
59,556 KB |
testcase_24 | AC | 211 ms
58,060 KB |
testcase_25 | AC | 187 ms
58,776 KB |
testcase_26 | AC | 222 ms
59,848 KB |
testcase_27 | AC | 204 ms
59,480 KB |
testcase_28 | AC | 195 ms
60,056 KB |
testcase_29 | AC | 234 ms
57,836 KB |
testcase_30 | AC | 242 ms
59,976 KB |
testcase_31 | AC | 213 ms
59,904 KB |
ソースコード
import java.util.*; import java.util.stream.*; import static java.lang.Math.*; public class Main{ public static void main(String... args){ Scanner sc=new Scanner(System.in); int k=sc.nextInt(); int n=sc.nextInt(); boolean[] isPrime=new boolean[n+1]; Arrays.fill(isPrime,true); isPrime[0]=false; isPrime[1]=false; for(int i=2;i<isPrime.length;i++){ if(!isPrime[i])continue; for(int j=2*i;j<isPrime.length;j+=i){ isPrime[j]=false; } } List<Integer> prime=new ArrayList<>(); for(int i=0;i<isPrime.length;i++){ if(isPrime[i])prime.add(i); } int ok=0; while(ok<prime.size()&&prime.get(ok)<k){ ok++; } int max=0; int maxLength=0; for(int i=ok;i<prime.size()-1&&prime.get(i)<=n;i++){ Set<Integer> set=new HashSet<>(); int j=i; while(j<prime.size()&&(!set.contains(sumNum(prime.get(j))))){ set.add(sumNum(prime.get(j))); //put(set); j++; } if(maxLength<=j-i){ maxLength=j-i; max=prime.get(i); } } put(max); } public static int sumNum(int x){ int result=0; for(char c:Integer.toString(x).toCharArray()){ result+=c-'0'; } if(result>=10){ return sumNum(result); }else{ return result; } } public static class Pair{ final int x,y; Pair(int x,int y){ this.x=x; this.y=y; } @Override public String toString(){ return String.format("Pair(%d,%d)",x,y); } } public static void print(Object object){ System.out.print(object); } public static void put(Object object) { System.out.println(object); } public static void put(){ System.out.println(); } public static void print(String format,Object... args){ System.out.print(String.format(format,args)); } public static void put(String format,Object... args) { System.out.println(String.format(format,args)); } }