Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- ifstream fin("extindere.in");
- ofstream fout("extindere.out");
- char negare(char c)
- {
- if(c=='1')
- return '2';
- else
- return '1';
- }
- string tento2(int n)
- {
- string s="";
- while(n>0)
- {
- if(n%2==0)
- s="0"+s;
- else
- s="1"+s;
- n=n/2;
- }
- if(s.length()%2==1)
- s="0"+s;
- return s;
- }
- char cautbin(int n)
- {
- string s=tento2(n-1);
- char c;
- int i;
- if(s[s.length()-1]==s[s.length()-2])
- c='1';
- else
- c='2';
- if(s.length()<3)
- return c;
- for(i=s.length()-3;i>=0;i=i-2)
- {
- if(s[i]!=s[i-1])
- c=negare(c);
- }
- return c;
- }
- int main()
- {
- int n;
- fin>>n;
- fout<<cautbin(n);
- return 0;
- }
Add Comment
Please, Sign In to add comment