結果

問題 No.434 占い
ユーザー 37zigen37zigen
提出日時 2020-04-04 05:15:54
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,212 bytes
コンパイル時間 2,320 ms
コンパイル使用メモリ 77,444 KB
実行使用メモリ 68,036 KB
最終ジャッジ日時 2023-09-16 05:24:49
合計ジャッジ時間 12,590 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 128 ms
55,668 KB
testcase_01 AC 131 ms
55,868 KB
testcase_02 AC 127 ms
55,548 KB
testcase_03 AC 127 ms
55,480 KB
testcase_04 AC 129 ms
54,232 KB
testcase_05 AC 127 ms
55,732 KB
testcase_06 AC 240 ms
57,484 KB
testcase_07 AC 145 ms
55,616 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 263 ms
59,044 KB
testcase_12 AC 359 ms
59,748 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 409 ms
61,388 KB
testcase_20 AC 946 ms
66,196 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 130 ms
55,872 KB
testcase_24 WA -
testcase_25 AC 258 ms
59,072 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		new Main().run();
	}
	
	int[] toint(char[] cs) {
		int[] ret=new int[cs.length];
		for(int i=0;i<ret.length;++i)ret[i]=(int)(cs[i]-'0');
		return ret;
	}
	
	int pow(int a,int n) {
		int ret=1;
		for(;n>0;n>>=1,a=a*a%9)if(n%2==1)ret=ret*a%9;
		return ret;
	}
	
	int inv(int a) {
		if(a%3==0)throw new AssertionError();
		return pow(a,5);
	}
	
	int count3(int a) {
		int ret=0;
		while(a%3==0) {
			a/=3;
			++ret;
		}
		return ret;
	}
	
	int mul(int...a) {
		int r=1;
		for(int v:a)r=r*v%9;
		return r;
	}

	void run() {
		Scanner sc=new Scanner(System.in);
		int T=sc.nextInt();
		while(T-->0) {
			int[] a=toint(sc.next().toCharArray());
			int n=a.length;
			int binom=1;
			int c3=0;
			int ans=0;
			boolean zero=Arrays.stream(a).filter(v->v==0).count()==n;
			for(int i=0;i<n;++i) {
				ans+=mul(pow(3,c3),binom,a[i]);
				ans%=9;
				int numerator=n-1-i;
				int denominator=i+1;
				while(numerator>0&&numerator%3==0) {
					numerator/=3;++c3;
				}
				while(denominator>0&&denominator%3==0) {
					denominator/=3;--c3;
				}
			}
			System.out.println(zero?0:(ans==0?9:ans));
		}
	}
}

0