結果
問題 | No.167 N^M mod 10 |
ユーザー | 37zigen |
提出日時 | 2016-04-11 12:01:48 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 222 ms / 1,000 ms |
コード長 | 1,111 bytes |
コンパイル時間 | 2,335 ms |
コンパイル使用メモリ | 78,040 KB |
実行使用メモリ | 57,860 KB |
最終ジャッジ日時 | 2023-10-22 00:03:34 |
合計ジャッジ時間 | 7,943 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge10 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 129 ms
57,480 KB |
testcase_01 | AC | 130 ms
57,456 KB |
testcase_02 | AC | 217 ms
57,740 KB |
testcase_03 | AC | 210 ms
57,832 KB |
testcase_04 | AC | 203 ms
57,688 KB |
testcase_05 | AC | 126 ms
57,488 KB |
testcase_06 | AC | 128 ms
57,376 KB |
testcase_07 | AC | 130 ms
57,444 KB |
testcase_08 | AC | 128 ms
57,176 KB |
testcase_09 | AC | 126 ms
57,396 KB |
testcase_10 | AC | 128 ms
57,404 KB |
testcase_11 | AC | 129 ms
57,300 KB |
testcase_12 | AC | 126 ms
57,444 KB |
testcase_13 | AC | 130 ms
57,452 KB |
testcase_14 | AC | 128 ms
55,432 KB |
testcase_15 | AC | 125 ms
57,448 KB |
testcase_16 | AC | 125 ms
57,412 KB |
testcase_17 | AC | 128 ms
57,468 KB |
testcase_18 | AC | 128 ms
57,480 KB |
testcase_19 | AC | 133 ms
57,480 KB |
testcase_20 | AC | 133 ms
57,164 KB |
testcase_21 | AC | 131 ms
57,648 KB |
testcase_22 | AC | 212 ms
57,860 KB |
testcase_23 | AC | 205 ms
57,748 KB |
testcase_24 | AC | 222 ms
57,756 KB |
testcase_25 | AC | 208 ms
57,736 KB |
testcase_26 | AC | 166 ms
57,512 KB |
testcase_27 | AC | 205 ms
57,672 KB |
testcase_28 | AC | 208 ms
57,676 KB |
ソースコード
import java.util.*; import java.math.*; public class Main{ public static void main(String[] args)throws Exception{ new Main().sovle(); } //0 0,0,0,0, //1 1,1,1,1, //2 2,4,8,6, //3 3,9,7,1, //4 4,6,4,6, //5 5,5,5,5, //6 6,6,6,6, //7 7,9,3,1, //8 8,4,2,6, //9 9,1,9,2, void sovle(){ Scanner sc=new Scanner(System.in); String N=sc.next(); String M=sc.next(); BigInteger nn=new BigInteger(N); nn=nn.mod(BigInteger.TEN); int n=nn.intValue(); BigInteger m=new BigInteger(M); if(m.equals(BigInteger.ZERO)){ System.out.println(1); return; } m=m.mod(BigInteger.valueOf(4)).add(BigInteger.valueOf(4)); //n^m mod 10 System.out.println(pow(n,m,10)); } int pow(int n,BigInteger m,int mod){ int ans=1; int pow=n; while(m.compareTo(BigInteger.ONE)>=0){ if(m.mod(BigInteger.valueOf(2)).equals(BigInteger.ZERO)){ pow*=pow; pow%=mod; m=m.divide(BigInteger.valueOf(2)); }else{ ans*=pow; ans%=mod; m=m.subtract(BigInteger.ONE); } } return ans; } void tr(Object...o){System.out.println(Arrays.deepToString(o));} }