Skip to content

Instantly share code, notes, and snippets.

@OmarJH
Created May 2, 2015 21:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OmarJH/9dcf2b5cab03594045e7 to your computer and use it in GitHub Desktop.
Save OmarJH/9dcf2b5cab03594045e7 to your computer and use it in GitHub Desktop.
ACM - UCV2013A - Counting Ids - SPOJ
#include <iostream>
using namespace std;
long long Bmode(int x, int p, int m)
{
long long tempo;
if (p == 0)
return 1;
if (p % 2 == 0)
{
tempo = Bmode(x, p / 2, m);
return (tempo*tempo) % m;
}
else
return (Bmode(x, p - 1, m)*(x%m)) % m;
}
int main()
{
int t, n,l;
long long m;
while (1)
{
cin >> n;
cin >> l;
if (n == 0 && l == 0)
break;
m = 0;
for (int i = 1; i <= l; i++)
{
m = (m + Bmode(n, i, 1000000007)) % 1000000007;
}
cout << m << endl;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment