結果
| 問題 |
No.64 XORフィボナッチ数列
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-02-05 00:27:31 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 5,000 ms |
| コード長 | 2,561 bytes |
| コンパイル時間 | 2,841 ms |
| コンパイル使用メモリ | 201,972 KB |
| 最終ジャッジ日時 | 2025-01-08 22:08:38 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 11 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:89:28: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
89 | lint f0,f1,n; scanf("%lld%lld%lld",&f0,&f1,&n);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using lint=long long;
template<class R>
class matrix{
vector<vector<R>> a;
public:
matrix(int n):a(n,vector<R>(n)){}
matrix(int m,int n):a(m,vector<R>(n)){}
matrix& operator+=(const matrix& A){
assert(h()==A.h() && w()==A.w());
int m=h(),n=w();
rep(i,m) rep(j,n) (*this)[i][j]+=A[i][j];
return *this;
}
matrix& operator-=(const matrix& A){
assert(h()==A.h() && w()==A.w());
int m=h(),n=w();
rep(i,m) rep(j,n) (*this)[i][j]-=A[i][j];
return *this;
}
matrix& operator*=(const matrix& A){
assert(w()==A.h());
int m=h(),n=w(),l=A.w();
matrix B(m,l);
rep(i,m) rep(j,l) rep(k,n) B[i][j]+=(*this)[i][k]*A[k][j];
swap(*this,B);
return *this;
}
matrix operator+(const matrix& A)const{ return matrix(*this)+=A; }
matrix operator-(const matrix& A)const{ return matrix(*this)-=A; }
matrix operator*(const matrix& A)const{ return matrix(*this)*=A; }
const vector<R>& operator[](int i)const{ return a[i]; }
vector<R>& operator[](int i){ return a[i]; }
vector<R> operator*(const vector<R>& v)const{
assert(w()==v.size());
int m=h(),n=w();
vector<R> res(m);
rep(i,m) rep(j,n) res[i]+=(*this)[i][j]*v[j];
return res;
}
int h()const{ return a.size(); }
int w()const{ return a.empty()?0:a[0].size(); }
static matrix identity(int n){
matrix I(n);
rep(i,n) I[i][i]=R{1};
return I;
}
};
template<class R>
matrix<R> pow(matrix<R> A,long long k){
assert(A.h()==A.w());
matrix<R> B=matrix<R>::identity(A.h());
for(;k>0;k>>=1){
if(k&1) B*=A;
A*=A;
}
return B;
}
class F2{
bool x;
public:
F2():x(false){}
F2(long long n){ assert(n==0||n==1); x=(n==1); }
F2& operator+=(const F2& a){ x=(x!=a.x); return *this; }
F2& operator-=(const F2& a){ return (*this)+=a; }
F2& operator*=(const F2& a){ x=(x&&a.x); return *this; }
F2& operator/=(const F2& a){ assert(a.x); return *this; }
F2 operator+(const F2& a)const{ return F2(*this)+=a; }
F2 operator-(const F2& a)const{ return F2(*this)-=a; }
F2 operator*(const F2& a)const{ return F2(*this)*=a; }
F2 operator/(const F2& a)const{ return F2(*this)/=a; }
bool operator==(const F2& a)const{ return x==a.x; }
bool operator!=(const F2& a)const{ return !((*this)==a); }
int to_int()const{ return x; }
};
int main(){
lint f0,f1,n; scanf("%lld%lld%lld",&f0,&f1,&n);
matrix<F2> A(2);
A[0][0]=0; A[0][1]=1;
A[1][0]=1; A[1][1]=1;
lint ans=0;
rep(i,60){
vector<F2> v={f0>>i&1,f1>>i&1};
if((pow(A,n)*v)[0]==1) ans+=1LL<<i;
}
printf("%lld\n",ans);
return 0;
}