結果
| 問題 |
No.303 割れません
|
| ユーザー |
piyoko_212
|
| 提出日時 | 2015-12-28 18:32:05 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 5,155 ms / 10,000 ms |
| コード長 | 2,026 bytes |
| コンパイル時間 | 2,071 ms |
| コンパイル使用メモリ | 77,992 KB |
| 実行使用メモリ | 100,356 KB |
| 最終ジャッジ日時 | 2024-09-19 07:50:37 |
| 合計ジャッジ時間 | 46,827 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 14 |
ソースコード
import java.util.*;
import java.math.*;
import java.io.*;
class Main{
public static void main(String[] args){
Scanner s=new Scanner(System.in);
int a=s.nextInt();
if(a==2){
System.out.println("3\nINF");
System.exit(0);
}
PrintWriter out = new PrintWriter(System.out);
out.println(a);
BigInteger mat[][]=new BigInteger[2][2];
BigInteger val[][]=new BigInteger[2][2];
BigInteger tmp[][]=new BigInteger[2][2];
mat[0][0]=mat[0][1]=mat[1][0]=BigInteger.ONE;
mat[1][1]=BigInteger.ZERO;
val[0][0]=val[1][1]=BigInteger.ONE;
val[0][1]=val[1][0]=BigInteger.ZERO;
tmp[0][0]=tmp[0][1]=tmp[1][0]=tmp[1][1]=BigInteger.ZERO;
int b=a;
if(a%2==0)b=a/2-1;
while(b>0){
if(b%2==1){
tmp[0][0]=val[0][0].multiply(mat[0][0]).add(val[0][1].multiply(mat[1][0]));
tmp[0][1]=val[0][0].multiply(mat[0][1]).add(val[0][1].multiply(mat[1][1]));
tmp[1][0]=val[1][0].multiply(mat[0][0]).add(val[1][1].multiply(mat[1][0]));
tmp[1][1]=val[1][0].multiply(mat[0][1]).add(val[1][1].multiply(mat[1][1]));
val[0][0]=tmp[0][0];
val[0][1]=tmp[0][1];
val[1][0]=tmp[1][0];
val[1][1]=tmp[1][1];
}
b/=2;
tmp[0][0]=mat[0][0].multiply(mat[0][0]).add(mat[0][1].multiply(mat[1][0]));
tmp[0][1]=mat[0][0].multiply(mat[0][1]).add(mat[0][1].multiply(mat[1][1]));
tmp[1][0]=mat[1][0].multiply(mat[0][0]).add(mat[1][1].multiply(mat[1][0]));
tmp[1][1]=mat[1][0].multiply(mat[0][1]).add(mat[1][1].multiply(mat[1][1]));
mat[0][0]=tmp[0][0];
mat[0][1]=tmp[0][1];
mat[1][0]=tmp[1][0];
mat[1][1]=tmp[1][1];
}
BigInteger ret;
if(a%2==0){
ret=val[1][0].multiply(val[0][0].shiftLeft(1));
}else{
ret=val[1][0];
}
out.println(ret.toString());
out.flush();
/*
BigInteger half=BigInteger.ZERO;
BigInteger tp=BigInteger.ONE;
BigInteger dn=BigInteger.ZERO;
for(int i=1;i<a;i++){
if(i*2==a){
half=tp.add(BigInteger.ZERO);
}
BigInteger nx=tp.add(dn);
dn=tp;tp=nx;
}
System.out.println((tp.subtract(half.multiply(half))).toString());
*/
}
}
piyoko_212