結果

問題 No.64 XORフィボナッチ数列
ユーザー chiho_miyakochiho_miyako
提出日時 2015-04-11 22:15:10
言語 Java21
(openjdk 21)
結果
AC  
実行時間 125 ms / 5,000 ms
コード長 1,915 bytes
コンパイル時間 2,043 ms
コンパイル使用メモリ 74,012 KB
実行使用メモリ 56,228 KB
最終ジャッジ日時 2023-09-17 19:18:39
合計ジャッジ時間 4,638 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
55,792 KB
testcase_01 AC 123 ms
55,992 KB
testcase_02 AC 125 ms
55,748 KB
testcase_03 AC 124 ms
55,820 KB
testcase_04 AC 123 ms
56,064 KB
testcase_05 AC 123 ms
55,852 KB
testcase_06 AC 123 ms
56,228 KB
testcase_07 AC 124 ms
55,940 KB
testcase_08 AC 125 ms
55,968 KB
testcase_09 AC 125 ms
56,060 KB
testcase_10 AC 122 ms
55,732 KB
testcase_11 AC 124 ms
55,520 KB
testcase_12 AC 123 ms
55,996 KB
testcase_13 AC 124 ms
56,112 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner koko = new Scanner(System.in);
        long zero = koko.nextLong();
        long one = koko.nextLong();
        long n = koko.nextLong();
        if(n%3==0){
            System.out.println(zero);
        }else if(n%3==1){
            System.out.println(one);
        }else{
            String tz = Long.toBinaryString(zero);
            String to = Long.toBinaryString(one);
            int min = Math.min(tz.length(),to.length());
            int max = Math.max(tz.length(),to.length());
            char[] ans = new char[max];
            if(tz.length()>to.length()){
                for(int i=0; i<min; i++){
                    if(tz.charAt(max-1-i)==to.charAt(min-1-i)){
                        ans[max-1-i] = '0';
                    }else{
                        ans[max-1-i] = '1';
                    }
                }
                for(int i=0; i<max-min; i++){
                        ans[i] = tz.charAt(i);
                }
            }else if(tz.length()<to.length()){
                for(int i=0; i<min; i++){
                    if(tz.charAt(min-1-i)==to.charAt(max-1-i)){
                        ans[max-1-i] = '0';
                    }else{
                        ans[max-1-i] = '1';
                    }
                }
                for(int i=0; i<max-min; i++){
                        ans[i] = to.charAt(i);
                } 
            }else{
                for(int i=0; i<min; i++){
                    if(tz.charAt(min-1-i)==to.charAt(max-1-i)){
                        ans[max-1-i] = '0';
                    }else{
                        ans[max-1-i] = '1';
                    }
                }
            }
            String an = String.valueOf(ans);
            long a = Long.parseLong(an,2);
            System.out.println(a);
        }
    }
}
0