Cod sursa(job #3132451)

Utilizator stefoni.mirceaStefoni Mircea stefoni.mircea Data 22 mai 2023 20:05:57
Problema Ridicare la putere in timp logaritmic Scor 0
Compilator c-64 Status done
Runda Arhiva educationala Marime 0.57 kb
#include <stdio.h>

const int n_max = 10001; 
const int m = 1999999973;

float exp_log(float x, int n)
{
    if (n < 0)
    {
        x = 1.0 / x;
        n = (-1) * n;
    }
    if (n == 0)
    {
        return 1;
    }
    float p = 1;
    while (n > 0)
    {
        if (n % 2)
        {
            p = p * x;
        }
        x = x * x;
        n = n / 2;
    }
    return p;
}

int main(void)
{
    unsigned int n, p;


    freopen("lgput.in","r",stdin);
	freopen("lgput.out","w",stdout);

    scanf("%d %d", &n, &p);

    printf("%g^%d = %g\n",n,p,exp_log(n,p));

    return 0;
}