Cod sursa(job #3162485)
| Utilizator | Data | 29 octombrie 2023 12:37:00 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | c-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.52 kb |
#include <stdio.h>
#include <stdlib.h>
#define M 1999999973
int main()
{
FILE *fin, *fout;
long long a, b, p;
fin = fopen( "lgput.in", "r" );
fscanf( fin, "%lld%lld", &a, &b );
fclose( fin );
p = 1;
while( b > 0 )
{
if( b % 2 == 1 )
{
p = ( p % M * a % M ) % M;
}
a = ( a % M * a % M ) % M;
b /= 2;
}
fout = fopen( "lgput.out", "w" );
fprintf( fout, "%lld", p );
fclose( fout );
return 0;
}
