結果

問題 No.167 N^M mod 10
ユーザー TLwiegehttTLwiegehtt
提出日時 2015-07-12 22:33:28
言語 C90
(gcc 11.4.0)
結果
AC  
実行時間 1 ms / 1,000 ms
コード長 1,198 bytes
コンパイル時間 437 ms
コンパイル使用メモリ 21,668 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-21 23:50:31
合計ジャッジ時間 1,389 ms
ジャッジサーバーID
(参考情報)
judge11 / judge9
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 0 ms
4,348 KB
testcase_03 AC 0 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 0 ms
4,348 KB
testcase_06 AC 0 ms
4,348 KB
testcase_07 AC 0 ms
4,348 KB
testcase_08 AC 0 ms
4,348 KB
testcase_09 AC 0 ms
4,348 KB
testcase_10 AC 0 ms
4,348 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 0 ms
4,348 KB
testcase_14 AC 0 ms
4,348 KB
testcase_15 AC 0 ms
4,348 KB
testcase_16 AC 0 ms
4,348 KB
testcase_17 AC 0 ms
4,348 KB
testcase_18 AC 0 ms
4,348 KB
testcase_19 AC 1 ms
4,348 KB
testcase_20 AC 0 ms
4,348 KB
testcase_21 AC 1 ms
4,348 KB
testcase_22 AC 1 ms
4,348 KB
testcase_23 AC 0 ms
4,348 KB
testcase_24 AC 1 ms
4,348 KB
testcase_25 AC 1 ms
4,348 KB
testcase_26 AC 0 ms
4,348 KB
testcase_27 AC 1 ms
4,348 KB
testcase_28 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:59:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   59 |         scanf("%s", n);
      |         ^~~~~~~~~~~~~~
main.c:60:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   60 |         scanf("%s", m);
      |         ^~~~~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>

int sub(char *s){
	int i, len;
	int mod = 0;
	int minus = 0;
	for(len=0;s[len] != '\0';len++);
	
	for(i=len-1;i>0 ;i--){
		if(minus == 1){
			if(s[i] == '0'){
				s[i] = '9';
				minus = 1;
			}else{
				char num = (char)(s[i] - '0' - 1);
				s[i] = (char)(num+'0');
				minus = 0;
			}
		}else{
			
			if( s[i] == '0'){
				s[i] = '9';
				minus = 1;
			}else{
				char num = (char)(s[i] - '0' - 1);
				s[i] = (char)(num+'0');
			}
		}
		
		if(minus == 0){break;}
	}
	
	for(i=0;i<len;i++){
		mod = mod*10 + (int)(s[i]-'0');
		mod = mod%4;
	}
	
	return mod+1;
}

int main(void){
	int ans[10][5] = {
		{0, 0, 0, 0, 0},
		{0, 1, 1, 1, 1},
		{0, 2, 4, 8, 6},
		{0, 3, 9, 7, 1},
		{0, 4, 6, 4, 6},
		{0, 5, 5, 5, 5},
		{0, 6, 6, 6, 6},
		{0, 7, 9, 3, 1},
		{0, 8, 4, 2, 6},
		{0, 9, 1, 9, 1}
	};
	int num;
	int lenN, lenM;
	int mul;
	char n[10010];
	char m[10010];
	scanf("%s", n);
	scanf("%s", m);
	
	for(lenN=0;n[lenN] != '\0';lenN++);
	for(lenM=0;m[lenM] != '\0';lenM++);
	
	num = (int)(n[lenN-1]-'0');
	
	if( lenM == 1 ){
		mul = (int)((m[0]-'0'-1)%4+1);
		if(m[0] == '0'){
			num = 1;
			mul = 1;
		}
	}else{
		mul = sub(m);
	}
	
	printf("%d\n", ans[num][mul]);
	
	return 0;
}
0