Cod sursa(job #2042189)

Utilizator alex2kamebossPuscasu Alexandru alex2kameboss Data 18 octombrie 2017 10:23:59
Problema Calcul Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.64 kb
#include <iostream>
#include <cstdio>
#include <string>

using namespace std;
unsigned int a,c,b,ant;
unsigned int s,m;
unsigned int pow(int p)
{
    int r=1;
    int b=10;
    while(p)
    {
        if(p%2==0)
        {
            b*=b;
            p/=2;
        }
        if(p%2==1)
        {
            r*=b;
            p--;
            b*=b;
            p/=2;
        }
    }
    return r;
}
int main()
{
    freopen("calcul.in","r",stdin);
    freopen("calcul.out","w",stdout);
    scanf("%d\n%x\n%d", &a,&b,&c);
    m=pow(c);
    ant=s=a;
    for(int i=1;i<b;i++)
    {
        ant=(ant*a)%m;
        s=(s+ant)%m;
    }
    cout<<s;
    return 0;
}