Mai intai trebuie sa te autentifici.
Cod sursa(job #970545)
| Utilizator | Data | 7 iulie 2013 10:50:13 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.76 kb |
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <string.h>
#include <stdlib.h>
using namespace std;
#define NMax 100000
unsigned long long m = 1999999973;
int Functionexpbysquaring(unsigned long long x,unsigned long long n)
{
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()
{
unsigned long long i, n, p;
unsigned long long 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;
}
