結果
| 問題 | No.28 末尾最適化 |
| コンテスト | |
| ユーザー |
akakimidori
|
| 提出日時 | 2015-07-27 00:04:07 |
| 言語 | C90 (gcc 12.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 746 bytes |
| 記録 | |
| コンパイル時間 | 219 ms |
| コンパイル使用メモリ | 22,400 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-16 00:21:17 |
| 合計ジャッジ時間 | 866 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | WA * 2 |
コンパイルメッセージ
main.c: In function ‘main’:
main.c:17:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
17 | scanf("%d",&Q);
| ^~~~~~~~~~~~~~
main.c:25:17: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
25 | scanf("%d%d%d%d",&seed[i],&N[i],&K[i],&B[i]);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include<stdio.h>
#include<stdlib.h>
#define M 1000
typedef long long int ln;
int comp(const void *c1,const void *c2){
int t1=*(int *)c1;
int t2=*(int *)c2;
return t1-t2;
}
int main(void){
int Q;
scanf("%d",&Q);
int seed[M];
int N[M];
int K[M];
int B[M];
int i;
for(i=0;i<Q;i++){
scanf("%d%d%d%d",&seed[i],&N[i],&K[i],&B[i]);
}
ln X[10001];
for(i=0;i<Q;i++){
X[0]=seed[i];
int j;
for(j=1;j<=N[i];j++){
X[j]=1+(X[j-1]*X[j-1]+X[j-1]*12345)%100000009;
}
int count[10001];
for(j=0;j<=N[i];j++){
count[j]=0;
while(X[j]%B[i]==0){
count[j]++;
X[j]/=B[i];
}
}
qsort(count,N[i]+1,sizeof(int),comp);
int res=0;
for(j=0;j<K[i];j++){
res+=count[j];
}
printf("%d\n",res);
}
return 0;
}
akakimidori