結果
| 問題 | No.6 使いものにならないハッシュ | 
| コンテスト | |
| ユーザー |  TLwiegehtt | 
| 提出日時 | 2015-07-17 22:26:49 | 
| 言語 | C90 (gcc 12.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 5 ms / 5,000 ms | 
| コード長 | 1,137 bytes | 
| コンパイル時間 | 584 ms | 
| コンパイル使用メモリ | 22,400 KB | 
| 実行使用メモリ | 5,376 KB | 
| 最終ジャッジ日時 | 2024-09-16 16:28:13 | 
| 合計ジャッジ時間 | 1,515 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 32 | 
コンパイルメッセージ
main.c: In function ‘main’:
main.c:52:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   52 |         scanf("%d", &K);
      |         ^~~~~~~~~~~~~~~
main.c:53:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   53 |         scanf("%d", &N);
      |         ^~~~~~~~~~~~~~~
            
            ソースコード
#include <string.h>
#include <stdio.h>
#define PMAX	(200100)
#define QMAX	(30)
char prime[PMAX];
void getPrime(int p){
    int i,j;
	
    for(i=0;i<p;i++){
        prime[i] = 1;
        if((i&1) == 0){
            prime[i] = 0;
        }
    }
    
    prime[0]=0;
    prime[1]=0;
    prime[2]=1;
	
    for(i=3;i*i<=p;i+=2){
        for(j=i+i;j<=p;j+=i){
            prime[j]=0;
        }
    }
}
int getHash(int num){
	int tmp = 0;
	while(num > 0){
		tmp = tmp + (num%10);
		num/=10;
	}
	
	if(tmp >= 10){
		tmp = getHash(tmp);
	}
	return tmp;
}
int main(void){
	int i,K,N;
	
	int sB;
	
	int cCnt = 0, cNum = 0;
	
	getPrime(PMAX);
	
	scanf("%d", &K);
	scanf("%d", &N);
	
	for(i=N;i>=K;i--){
		int hash[12]={0};
		int tNum = 0;
		int tCnt = 0;
		
		if(prime[i] != 1){continue;}
		
		for(sB=i;sB>=K;sB--){
			if(prime[sB] == 1){
				int tmp = getHash(sB);
				if(hash[tmp] == 1){
					break;
				}
				tNum = sB;
				tCnt = tCnt+1;
				hash[tmp] = 1;
//				printf("%d %d\n", sB, tmp);
			}
		}
		
		if(cCnt < tCnt){
			cCnt = tCnt;
			cNum = tNum;
		}
		
//		printf("-%d %d-\n", tNum, tCnt);
	}
	
	printf("%d\n", cNum);
	
	return 0;
}
            
            
            
        