Cod sursa(job #1996714)

Utilizator al_k_ponyClaudiu Babin al_k_pony Data 2 iulie 2017 14:19:09
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.75 kb
# pragma GCC optimize("O3")
# include <bits/stdc++.h>
# define maxn 100005
# define ll long long
# define clock (clock() * 1000.0 / CLOCKS_PER_SEC)
# define rc(s) return cout << s,0
# define _ ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
# define db(x) cerr << #x << " = " << x << '\n'
# define pb push_back
# define mp make_pair
# define sz(x) (int)((x).size())
# define int ll
using namespace std;

int mod = 1999999973;

int exp(int n,int p)
{
	int ans = 1;
	for(int i = 0;(1 << i) <= p;i++)
	{
		if(p & (1 << i))
		{
			ans *= n;
			ans %= mod;
		}
		n *= n;
		n %= mod;
	}
	return ans;
}
int32_t main(){_
    freopen("lgput.in","r",stdin);
    freopen("lgput.out","w",stdout);
    int n,p;
    cin >> n >> p;
    rc(exp(n,p));
	return 0;
}