結果
| 問題 | No.6 使いものにならないハッシュ |
| コンテスト | |
| ユーザー |
roaiziro
|
| 提出日時 | 2015-09-30 12:17:28 |
| 言語 | C90 (gcc 12.3.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 5,000 ms |
| コード長 | 1,760 bytes |
| 記録 | |
| コンパイル時間 | 687 ms |
| コンパイル使用メモリ | 21,760 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-09-16 16:30:10 |
| 合計ジャッジ時間 | 1,857 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 32 |
コンパイルメッセージ
main.c: In function ‘main’:
main.c:93:5: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
93 | scanf("%d", &k);
| ^~~~~~~~~~~~~~~
main.c:94:5: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
94 | scanf("%d", &n);
| ^~~~~~~~~~~~~~~
ソースコード
#include<stdio.h>
#define N 200001
#define HN 18000
#define HS 10
struct HASHNODE{
int p, h;
}hashnode[HN];
int noden;
int nemu[N], prime[N], hashtable[HS];
int hash(int n)
{
int h = 0, mod;
while(0 < n){
mod = n % 10;
h += mod;
n /= 10;
}
if(10 <= h){
h = hash(h);
}
return(h);
}
int p(int n)
{
int i, j;
for(i = 1; i <= n; i++){
nemu[i] = i;
}
nemu[1] = 0;
for(i = 2; i*i <= n; i++){
for(j = i; i*j <= n; j++){
nemu[i*j] = 0;
}
}
return(0);
}
int hashnodecreate(int k, int n)
{
noden = 1;
while(k <= n){
if(nemu[k]){
hashnode[noden].p = nemu[k];
hashnode[noden].h = hash(nemu[k]);
noden++;
}
k++;
}
return(noden);
}
void cmb(void)
{
int i, j, k, w[HS];
for(i = 1; i < noden; i++){
for(k = 1; k < HS; k++){
w[k] = 0;
}
for(j = i; j < noden; j++){
if(w[hashnode[j].h] == 0){
w[hashnode[j].h] = 1;
}else{
break;
}
}
if(hashnode[hashtable[j - i]].p < hashnode[i].p){
hashtable[j - i] = i;
}
}
return;
}
void ans(void)
{
int i;
for(i = HS-1; 0 < i; i--){
if(hashtable[i]){
printf("%d\n", hashnode[hashtable[i]].p);
break;
}
}
}
int main(int argc, const char * argv[])
{
int k, n, i, j;
scanf("%d", &k);
scanf("%d", &n);
p(n);
j = hashnodecreate(k, n);
// for(i = 1; i < j; i++){
// printf("p=%d hash=%d\n", hashnode[i].p, hashnode[i].h);
// }
// printf("j=%d\n", j);
cmb();
ans();
return 0;
}
roaiziro