Untitled

mail@pastecode.io avatar
unknown
plain_text
5 months ago
1.1 kB
0
Indexable
#include <bits/stdc++.h>
#define endl '\n'
#define maxn 105
#define TASK bai1
#define For(i,a,b) for ( int i = a; i <= b; i++ )
#define Ford(i,a,b) for ( int i = a; i >= b; i-- )
#define MOD 100000000000007

using namespace std;
long long n;
long long luythua(int x, int y)
{
    if(y == 0) return 1;
    if(y % 2 == 0)
    {
    long long half = luythua(x,y / 2);
    return half*half;
    }
    else return x*luythua(x,y - 1);
}

int Findk(long long x)
{
    int i = 0;
    while(luythua(2,i) < x)
    i++;
    return i;
}

void solve()
{
    if(n == 1)
    {
        cout << 0 << endl;
        return;
    }
    if(n == 2)
    {
        cout << 1 << endl;
        return;
    }
    int x = Findk(n),res = 0;
    while(x != 0)
    {
    if(n > luythua(2,x))
    {
        n -= luythua(2,x);
        res++;
    }
    x--;
    }
    cout << (n-1 + res) % 3 << endl;
}
void inp()
{
    while(cin >> n)
    solve();
}
int main()
{
    ios_base:: sync_with_stdio(0);
    cin.tie(0);
    if(fopen("bai1.inp","r")){
        freopen("bai1.inp","r",stdin);
    }
    inp();
}
Leave a Comment