Skip to content

Commit 05440f3

Browse files
committed
Fibonacci_xor problem added
1 parent 3a750ee commit 05440f3

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

fibonacci_xor.cpp

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//Fibonacci XOR
2+
/*You are given three integers a, b, and n, calculate f(n), where f(n) is the xor of last two numbers
3+
i.e, f(n) = f(n-1)?f(n-2), where ? is xor operation.
4+
*/
5+
6+
7+
#include<bits/stdc++.h>
8+
using namespace std;
9+
int main()
10+
{
11+
int a,b,n;
12+
13+
cin>>a>>b>>n;
14+
int rem=n%3;
15+
if(rem==0) cout<<a<<endl;
16+
else if(rem==1) cout<<b<<endl;
17+
else cout<<(a^b)<<endl;
18+
19+
return 0;
20+
}
21+

0 commit comments

Comments
 (0)