Cod sursa(job #1479162)

Utilizator GosulyGosuly Robert Gosuly Data 30 august 2015 17:32:45
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator c Status done
Runda Arhiva educationala Marime 0.63 kb
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

unsigned long hatLog(unsigned long n,unsigned long hat)
{

    printf("%lu %lu\n",n,hat);

    if(hat!=1)
    {
        if(hat%2==0)
            return hatLog(n*n,hat/2);
        else
            return hatLog(n*n,hat/2)*n;
    }
    else
        return n;

}
int main()
{
    FILE *readfile,*writefile;
    readfile=fopen("lgput.in","r");
    writefile=fopen("lgput.out","w");

    unsigned long alap;
    unsigned long hat;

    fscanf(readfile,"%lu %d",&alap,&hat);


    fprintf(writefile,"%lu",hatLog(alap,hat)% 1999999973);
    return 0;
}