結果

問題 No.435 占い(Extra)
コンテスト
ユーザー testestest
提出日時 2016-10-15 04:29:47
言語 C90
(gcc 12.4.0)
コンパイル:
gcc-12 -O2 -std=c90 -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
AC  
実行時間 203 ms / 2,000 ms
コード長 412 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 203 ms
コンパイル使用メモリ 32,992 KB
最終ジャッジ日時 2026-02-23 22:34:27
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 32
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c:1:1: warning: data definition has no type or storage class
    1 | x,a,b,m,n,i,t,ans,c,c3;
      | ^
main.c:2:1: warning: data definition has no type or storage class
    2 | inv9[]={0,1,5,0,7,2,0,4,8};
      | ^~~~
main.c: In function ‘main’:
main.c:6:23: warning: incompatible implicit declaration of built-in function ‘scanf’ [-Wbuiltin-declaration-mismatch]
    6 |         for(gets(&i);~scanf("%d%d%d%d%d",&n,&x,&a,&b,&m);){
      |                       ^~~~~
main.c:1:1: note: include ‘<stdio.h>’ or provide a declaration of ‘scanf’
  +++ |+#include <stdio.h>
    1 | x,a,b,m,n,i,t,ans,c,c3;
main.c:16:17: warning: incompatible implicit declaration of built-in function ‘printf’ [-Wbuiltin-declaration-mismatch]
   16 |                 printf("%d\n",ans%9?:t?9:0);
      |                 ^~~~~~
main.c:16:17: note: include ‘<stdio.h>’ or provide a declaration of ‘printf’
/usr/bin/ld: /tmp/ccKIZ7LH.o: in function `main':
main.c:(.text.startup+0x22): 警告: the `gets' function is dangerous and should not be used.

ソースコード

diff #
raw source code

x,a,b,m,n,i,t,ans,c,c3;
inv9[]={0,1,5,0,7,2,0,4,8};
f3(n){int i=0;for(;n&&n%3==0;n/=3)i++;return i;}
g3(n){for(;n&&n%3==0;n/=3);return n;}
main(){
	for(gets(&i);~scanf("%d%d%d%d%d",&n,&x,&a,&b,&m);){
		n--;
		t=ans=c3=0,c=1;
		for(i=0;i<=n;i++){
			t+=x%10;
			ans+=c*(c3?c3==1?3:0:1)*(x%10)%9;
			c3+=f3(n-i)-f3(i+1);
			c=(c*g3(n-i)*inv9[g3(i+1)%9])%9;
			x=((x^a)+b)%m;
		}
		printf("%d\n",ans%9?:t?9:0);
	}
}
0