結果
問題 |
No.6 使いものにならないハッシュ
|
ユーザー |
|
提出日時 | 2016-03-08 02:51:10 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 177 ms / 5,000 ms |
コード長 | 1,483 bytes |
コンパイル時間 | 2,455 ms |
コンパイル使用メモリ | 79,332 KB |
実行使用メモリ | 45,620 KB |
最終ジャッジ日時 | 2024-09-16 16:33:02 |
合計ジャッジ時間 | 8,391 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge6 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 32 |
ソースコード
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; } }