結果
| 問題 |
No.344 ある無理数の累乗
|
| コンテスト | |
| ユーザー |
mits58
|
| 提出日時 | 2016-07-09 00:51:48 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 128 ms / 2,000 ms |
| コード長 | 766 bytes |
| コンパイル時間 | 3,429 ms |
| コンパイル使用メモリ | 76,760 KB |
| 実行使用メモリ | 41,420 KB |
| 最終ジャッジ日時 | 2024-10-13 07:54:45 |
| 合計ジャッジ時間 | 6,770 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 30 |
ソースコード
import java.util.Scanner;
class Main{
static int[][] I={{1,0},{0,1}};
static int mod=1000;
static int[][] pow(int[][] a,int x){
if(x==1 || x==0) return a;
else if(x%2==0) return pow(mul(a,a),x/2);
else return mul(pow(mul(a,a),x/2),a);
}
static int[][] mul(int[][] a,int[][] b){
int[][] res=new int[2][2];
for(int i=0;i<2;i++){
for(int j=0;j<2;j++){
for(int k=0;k<2;k++){
res[i][j]+=a[i][k]*b[k][j];
res[i][j]%=mod;
}
}
}
return res;
}
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
while(sc.hasNext()){
int n=sc.nextInt();
int[][] a={{1,3},{1,1}};
int[][] ans=pow(a,n);
if(n==0) System.out.println(1);
else System.out.println((2*ans[0][0]+(n%2==0 ? -1 : 0))%mod);
}
}
}
mits58