Pagini recente » Cod sursa (job #380162) | 12345678901 | Cod sursa (job #285188) | Cod sursa (job #141416) | Cod sursa (job #759146)
Cod sursa(job #759146)
#include <fstream>
using namespace std;
typedef long long ll;
const ll mod = 666013;
ll nr (ll n) {
if (n < 2) {
return 1;
}
if (n == 2) {
return 2;
}
if (! (n & (n - 1))) {
return n;
}
if (! (n & (n + 1))) {
return 1;
}
if (n & 1) {
ll t = nr (n >> 1ll);
t = (t * t) % mod;
return t;
}
else {
ll t1, t2;
t1 = nr (n >> 1ll);
n --;
t2 = nr (n >> 1ll);
t1 = (t1 * t2) % mod;
t1 <<= 1ll;
if (t1 >= mod) {
t1 -= mod;
}
return t1;
}
}
int main () {
int i, q;
ll n;
ifstream f ("ciuperci.in");
ofstream g ("ciuperci.out");
f >> q;
while (q --) {
f >> n;
g << nr (n) << '\n';
}
f.close ();
g.close ();
return 0;
}