結果
| 問題 | No.6 使いものにならないハッシュ | 
| コンテスト | |
| ユーザー |  char134217728 | 
| 提出日時 | 2017-08-19 03:12:39 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 11 ms / 5,000 ms | 
| コード長 | 1,176 bytes | 
| コンパイル時間 | 1,621 ms | 
| コンパイル使用メモリ | 163,852 KB | 
| 実行使用メモリ | 5,376 KB | 
| 最終ジャッジ日時 | 2024-09-16 16:41:22 | 
| 合計ジャッジ時間 | 2,714 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 32 | 
コンパイルメッセージ
main.cpp:37:1: warning: ISO C++ forbids declaration of ‘main’ with no type [-Wreturn-type]
   37 | main(){
      | ^~~~
main.cpp: In function ‘int main()’:
main.cpp:64:11: warning: ‘ans’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   64 |   cout << ans << endl;
      |           ^~~
            
            ソースコード
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef set<int> si;
const int inf = 1e9;
const int mod = 1e9+7;
vi pl;
bool is_prime(int a){
  if(a < 2)return false;
  for(vi::iterator itr = pl.begin(); itr != pl.end(); itr++){
    if(*itr * *itr > a)break;
    if(a % (*itr) == 0)return false;
  }
  return true;
}
int to_h(int a){
  if(a < 10)return a;
  while(a > 10){
    int s = 0;
    while(a > 0){
      s += a % 10;
      a /= 10;
    }
    a = s;
  }
  return a;
}
queue<int> q;
bool z[10];
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  FOR(i, 2, 501){
    if(is_prime(i))pl.pb(i);
  }
  int maxl = 0, ans;
  int k, n;
  cin >> k >> n;
  FORR(i, n, k){
    if(!is_prime(i))continue;
    int h = to_h(i);
    if(z[h]){
      while(true){
        int f = q.front();
        q.pop();
        z[f] = false;
        if(f == h)break;
      }
    }
    q.push(h);
    z[h] = true;
    if(maxl < q.size()){
      maxl = q.size();
      ans = i;
    }
  }
  cout << ans << endl;
}
            
            
            
        