結果

問題 No.403 2^2^2
コンテスト
ユーザー akakimidori
提出日時 2017-06-09 02:04:32
言語 C90(gcc15)
(gcc 15.2.0)
コンパイル:
gcc-15 -O2 -std=c90 -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
WA  
実行時間 -
コード長 781 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 326 ms
コンパイル使用メモリ 40,068 KB
最終ジャッジ日時 2026-02-24 00:42:00
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23 WA * 4
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<stdio.h>

typedef long long int ln;

int phi(int n){
  int res=1;
  if(n%2==0){
    n/=2;
    while(n%2==0){
      res*=2;
      n/=2;
    }
  }
  int k=3;
  while(k*k<=n){
    if(n%k==0){
      res*=k-1;
      n/=k;
      while(n%k==0){
	res*=k;
	n/=k;
      }
    }
    k+=2;
  }
  if(n>1){
    res*=n-1;
  }
  return res;
}

int modPow(ln r,ln n,int mod){
  r=r%mod;
  n=n%phi(mod);
  ln res=1;
  ln t=r;
  while(n>0){
    res=res*(n&0x01?t:1)%mod;
    t=t*t%mod;
    n>>=1;
  }
  return res;
}

void run(void){
  ln a,b,c;
  scanf("%lld^%lld^%lld",&a,&b,&c);
  const int p=1000000007;

  int a_bc=modPow(a,b%(p-1)*(c%(p-1)),p);
  int b_c=modPow(b,c,p-1);
  int a_b_c=modPow(a,b_c,p);
  printf("%d %d\n",a_bc,a_b_c);
  return;
}

int main(void){
  run();
  return 0;
}
0