結果
問題 | No.6 使いものにならないハッシュ |
ユーザー |
![]() |
提出日時 | 2015-04-17 02:37:57 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 26 ms / 5,000 ms |
コード長 | 971 bytes |
コンパイル時間 | 419 ms |
コンパイル使用メモリ | 51,024 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-16 16:24:55 |
合計ジャッジ時間 | 1,699 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 32 |
コンパイルメッセージ
main.cpp: In function ‘int getInt()’: main.cpp:5:34: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 5 | inline int getInt(){ int s; scanf("%d", &s); return s; } | ~~~~~^~~~~~~~~~
ソースコード
#define REP(i,n) for(int i=0; i<(int)(n); i++) #include <queue> #include <cstdio> inline int getInt(){ int s; scanf("%d", &s); return s; } #include <set> using namespace std; int main(){ const int k = getInt(); const int n = getInt(); vector<int> p; vector<int> h; for(int i = max(2, k); i <= n; i++){ bool ok = true; for(int j = 2; j * j <= i; j++) if(i % j == 0){ ok = false; break; } if(!ok) continue; p.push_back(i); int hh = i; while(hh >= 10){ int t = 0; while(hh){ t += hh % 10; hh /= 10; } hh = t; } h.push_back(hh); } int len = 0; int ans = 0; int fst = 0; set<int> s; REP(i,p.size()){ if(s.count(h[i])){ do{ s.erase(h[fst]); }while(h[fst++] != h[i]); } s.insert(h[i]); // printf("%d(%d): %d\n", p[i], h[i], p[fst]); if(len <= i - fst + 1){ len = i - fst + 1; ans = p[fst]; } } printf("%d\n", ans); return 0; }