結果

問題 No.181 A↑↑N mod M
コンテスト
ユーザー testestest
提出日時 2016-10-25 03:39:43
言語 C90
(gcc 12.4.0)
コンパイル:
gcc-12 -O2 -std=c90 -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
WA  
実行時間 -
コード長 356 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 288 ms
コンパイル使用メモリ 32,640 KB
最終ジャッジ日時 2026-02-23 22:43:09
ジャッジサーバーID
(参考情報)
judge2 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 6
other AC * 33 WA * 4
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c:14:1: warning: data definition has no type or storage class
   14 | a,n,m;
      | ^
main.c: In function ‘main’:
main.c:16:9: warning: incompatible implicit declaration of built-in function ‘scanf’ [-Wbuiltin-declaration-mismatch]
   16 |         scanf("%d%d%d",&a,&n,&m);
      |         ^~~~~
main.c:1:1: note: include ‘<stdio.h>’ or provide a declaration of ‘scanf’
  +++ |+#include <stdio.h>
    1 | gcd(p,q){return q?gcd(q,p%q):p;}
main.c:17:9: warning: incompatible implicit declaration of built-in function ‘printf’ [-Wbuiltin-declaration-mismatch]
   17 |         printf("%d",mod4(a,n,m));
      |         ^~~~~~
main.c:17:9: note: include ‘<stdio.h>’ or provide a declaration of ‘printf’

ソースコード

diff #
raw source code

gcd(p,q){return q?gcd(q,p%q):p;}
phi(m){
	int i,s=0;
	for(i=1;i<m;i++)s+=gcd(m,i)==1;
	return s;
}
mod3(a,n,m){return n?n%2?mod3(a*a%m,n/2,m)*a%m:mod3(a*a%m,n/2,m):1;}
mod4(a,n,m){
	if(m==1)return 0;
	if(n==0)return 1;
	return mod3(a%m,mod4(a,n-1,phi(m))+(m-1)*phi(m),m);
}

a,n,m;
main(){
	scanf("%d%d%d",&a,&n,&m);
	printf("%d",mod4(a,n,m));
	return 0;
}
0