Pagini recente » Cod sursa (job #2269814) | Cod sursa (job #3334667) | Monitorul de evaluare | Cod sursa (job #981247) | Cod sursa (job #970538)
Cod sursa(job #970538)
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <string.h>
#include <stdlib.h>
using namespace std;
#define NMax 100000
const int m = 1999999973;
int Functionexpbysquaring(long long int x,long long int n)
{
if (n < 0) return Functionexpbysquaring(1/x,-n);
else if (n == 0) return 1;
else if (n == 1) return x % m;
else if (n % 2 == 0) return Functionexpbysquaring(((x%m)*(x%m)) % m, n/2);
else if (n % 2 != 0) return x * Functionexpbysquaring(((x%m)*(x%m)) % m, (n-1)/2);
}
int main()
{
long long int i, n, p;
long long int sol;
FILE *f = fopen("lgput.in", "r");
FILE *g = fopen("lgput.out", "w");
fscanf(f, "%lld %lld", &n, &p);
sol = Functionexpbysquaring(n%m, p);
fprintf(g, "%lld", sol%m);
fclose(g);
return 0;
}