結果

問題 No.6 使いものにならないハッシュ
ユーザー AuroraAurora
提出日時 2022-04-23 17:45:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 79 ms / 5,000 ms
コード長 971 bytes
コンパイル時間 1,759 ms
コンパイル使用メモリ 170,004 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-07 10:43:11
合計ジャッジ時間 4,843 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 79 ms
4,376 KB
testcase_03 AC 8 ms
4,376 KB
testcase_04 AC 14 ms
4,380 KB
testcase_05 AC 16 ms
4,376 KB
testcase_06 AC 41 ms
4,376 KB
testcase_07 AC 23 ms
4,376 KB
testcase_08 AC 36 ms
4,380 KB
testcase_09 AC 15 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 9 ms
4,380 KB
testcase_12 AC 47 ms
4,380 KB
testcase_13 AC 9 ms
4,380 KB
testcase_14 AC 15 ms
4,376 KB
testcase_15 AC 36 ms
4,376 KB
testcase_16 AC 29 ms
4,380 KB
testcase_17 AC 60 ms
4,376 KB
testcase_18 AC 75 ms
4,380 KB
testcase_19 AC 58 ms
4,380 KB
testcase_20 AC 48 ms
4,380 KB
testcase_21 AC 5 ms
4,380 KB
testcase_22 AC 54 ms
4,376 KB
testcase_23 AC 46 ms
4,376 KB
testcase_24 AC 50 ms
4,380 KB
testcase_25 AC 27 ms
4,380 KB
testcase_26 AC 64 ms
4,380 KB
testcase_27 AC 47 ms
4,380 KB
testcase_28 AC 25 ms
4,376 KB
testcase_29 AC 67 ms
4,376 KB
testcase_30 AC 56 ms
4,376 KB
testcase_31 AC 51 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

int main(){
  long long int K,N;
  cin >> K >> N;
  vector<long long int> P(0);
  for(long long int i=K;i<=N;i++){
    if(i == 1) continue;
    bool flag = true;
    for(long long int j=2;j*j<=i;j++){
      if(i%j == 0){
        flag = false;
        break;
      }
    }
    if(flag) P.push_back(i);
  }
  vector<long long int> A(P.size());
  for(int i=0;i<P.size();i++){
    A[i] = P[i];
    while(A[i] >= 10){
      long long int S = 0;
      while(A[i] > 0){
        S += A[i]%10;
        A[i] /= 10;
      }
      A[i] = S;
    }
  }
  for(int i=9;i>=1;i--){
    int ans = -1;
    for(int j=0;j<(int)P.size()-i+1;j++){
      vector<bool> used(10,false);
      bool ok = true;
      for(int k=j;k<j+i;k++){
        if(used[A[k]]){
          ok = false;
          break;
        }
        else used[A[k]] = true;
      }
      if(ok) ans = P[j];
    }
    if(ans != -1){
      cout << ans << endl;
      break;
    }
  }
}
0