Cod sursa(job #1824960)
Utilizator | Data | 8 decembrie 2016 16:54:53 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.45 kb |
#include <cstdio>
using namespace std;
const int mod = 1999999973 ;
int main()
{
freopen("lgput.in","r",stdin);
freopen("lgput.out","w",stdout);
int n , p ;
scanf("%d %d",&n,&p);
long long sol = 1 ;
while ( p > 0 )
{
if ( p % 2 == 1 )
{
sol = ( sol * n ) % mod ;
p-- ;
}
n = ( n * n ) % mod ;
p = p / 2 ;
}
printf("%lld",sol);
}