結果

問題 No.435 占い(Extra)
ユーザー cielciel
提出日時 2020-02-09 00:06:54
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 1,054 bytes
コンパイル時間 272 ms
コンパイル使用メモリ 32,896 KB
実行使用メモリ 45,848 KB
最終ジャッジ日時 2024-04-17 03:06:33
合計ジャッジ時間 6,107 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 69 ms
45,780 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 205 ms
45,636 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int I[]={-1,1,5,-1,7,2,-1,4,8};
unsigned char Fk[10000001];
int Fz[10000001];
int getFk(int i){
	return (Fk[i/2]>>(i%2^1)*4)&0xf;
}
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){
	int k0=getFk(n),k1=getFk(k),k2=getFk(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<=10000000;i++){
		int k0=getFk(i-1);
		int z0=Fz[i-1];
		int k1,z1;
		z(i,&k1,&z1);
		Fk[i/2]|=(k0*k1%9)<<i%2*4;
		Fz[i]=z0+z1;
	}
	int T,r;
	for(scanf("%d",&T),getchar();T--;){
		bool f=true;
		r=0;
#if 1
		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