結果
| 問題 | No.6 使いものにならないハッシュ | 
| コンテスト | |
| ユーザー |  goodbaton | 
| 提出日時 | 2014-11-23 17:02:48 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 8 ms / 5,000 ms | 
| コード長 | 1,476 bytes | 
| コンパイル時間 | 641 ms | 
| コンパイル使用メモリ | 66,460 KB | 
| 実行使用メモリ | 5,376 KB | 
| 最終ジャッジ日時 | 2024-09-16 16:22:39 | 
| 合計ジャッジ時間 | 1,624 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 32 | 
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:43:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   43 |     scanf("%d%d",&k,&n);
      |     ~~~~~^~~~~~~~~~~~~~
            
            ソースコード
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
using namespace std;
bool so[200010];
int syaku[2][100000];
void sosu(){
    so[0]=so[1]=true;
    for(int i=2;i<=200000;i++){
        if(!so[i])
            for(int j=2;j*i<=200000;j++){
                so[j*i]=true;
            }
    }
}
int Hash(int num){
    int re=0,p,k=log10(num);
    for(int i=k;i>=0;i--){
        p = pow(10,i);
        re+=num/p;
        num=num%p;
    }
    if(re>=10)
        return Hash(re);
    else
        return re;
}
int main(){
    int k,n,j,l=0,r=0,ch[10]={0},max_lr=-1,max_s=0;
    sosu();
    
    scanf("%d%d",&k,&n);
    
    j=0;
    for(int i=k;i<=n;i++){
        if(!so[i]){
            syaku[0][j]=Hash(i);
            syaku[1][j]=i;
            j++;
        }
    }
    
    //shakutori
    while(r<=j){
        if(max_lr<=r-l){
            max_lr=r-l;
            max_s=syaku[1][l];
        }
        
        for(int i=l;i<=r;i++){
            if(ch[syaku[0][i]]){
                l++;
                break;
            }
            ch[syaku[0][i]]=1;
            if(i==r){
                r++;
                break;
            }
        }
        for(int i=0;i<10;i++){
            ch[i]=0;
        }
        
    }
    
    printf("%d\n",max_s);
    
    
    return 0;
}
            
            
            
        