Cod sursa(job #1522453)

Utilizator akaprosAna Kapros akapros Data 11 noiembrie 2015 18:48:18
Problema Ciuperci Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.93 kb
#include <cstdio>
#include <cstring>
#include <algorithm>
#define mod 666013
using namespace std;
int n, q;
void read()
{
    freopen("ciuperci.in", "r", stdin);
    scanf("%d", &q);
}
void solve(int n, long long &x, long long &y)
{
    if (n == 0)
    {
        x = 1;
        y = 1;
        return ;
    }
    if (n == 1)
    {
        x = 2;
        y = 1;
        return ;
    }
    long long a, b;
    if (n & 1)
    {
        solve(n >> 1, a, b);
        y = (b * b * 1LL) % mod;
        x = (2 * a * b * 1LL) % mod;
    }else
    {
        solve((n >> 1) - 1, a, b);
        x = (a * a * 1LL) % mod;
        y = (2 * a * b * 1LL) % mod;
    }
}
void write()
{
    long long a, b, x;
    freopen("ciuperci.out", "w", stdout);
    while (q --)
    {
        scanf("%lld", &x);
        solve(x, a, b);
        printf("%lld\n", b);
    }
}
int main()
{
    read();
    write();
    return 0;
}