Created
May 2, 2015 21:22
-
-
Save OmarJH/9dcf2b5cab03594045e7 to your computer and use it in GitHub Desktop.
ACM - UCV2013A - Counting Ids - SPOJ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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