結果

問題 No.432 占い(Easy)
ユーザー cielciel
提出日時 2016-10-18 02:11:25
言語 C90
(gcc 11.4.0)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 964 bytes
コンパイル時間 964 ms
コンパイル使用メモリ 26,436 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-14 15:59:59
合計ジャッジ時間 2,033 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,384 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <string.h>
#include <stdbool.h>

int I[]={-1,1,5,-1,7,2,-1,4,8};
char Fk[10000001];
int Fz[10000001];
void z(int n,int *n_,int *r_){
	int r=0;
	for(;n%3==0;n/=3)r++;
	*n_=n,*r_=r;
}
int comb(int n,int k){
	char k0=Fk[n],k1=Fk[k],k2=Fk[n-k];
	int z0=Fz[n],z1=Fz[k],z2=Fz[n-k];
	int z=z0-z1-z2,r=(int)k0*I[k1]*I[k2]%9;
	return z==0 ? r : z==1 ? r*3%9 : 0;
}
int main(){
	int i;
	Fk[0]=1,Fz[0]=0;
	for(i=1;i<=1000;i++){
		char k0=Fk[i-1];
		int z0=Fz[i-1];
		int k1,z1;
		z(i,&k1,&z1);
		Fk[i]=k0*k1%9;
		Fz[i]=z0+z1;
	}
	int T,r;
	for(scanf("%d",&T),getchar();T--;){
		bool f=true;
		r=0;
#if 0
		int n,x,a,b,m;
		scanf("%d%d%d%d%d",&n,&x,&a,&b,&m);
		for(i=0;i<n;i++){
			int c=x%10;
			r=(r+c*comb(n-1,i))%9;
			if(c)f=false;
			x=((x^a)+b)%m;
		}
#else
		char s[100001];
		scanf(" %s",s);
		int n=strlen(s);
		for(i=0;i<n;i++){
			r=(r+(s[i]-48)*comb(n-1,i))%9;
			if(s[i]!=48)f=false;
		}
#endif
		printf("%d\n",r!=0||f ? r : 9);
	}
}
0