Header Ads

Learn Together, Stay Connected.

ধারার যোগফল-C


#include <stdio.h>
const int p = 10007;
int main()
{
long long a, ans = 0;
long long n; scanf("%lld %lld", &a, &n);
a %= p;
int cum[p]; cum[0] = 0;
int i = 1, rem = 1, j;
if(n >= p) j = p - 1;
else j = n;

if(a!=0)
for(i = 1; i <= j; i++)
{
rem = (rem * a) % p;
ans = (ans + rem) % p;
cum[i] = ans;
}

long long fac = n / (p - 1);

if(fac!=0)
{
ans = (ans * (fac % p)) % p;
ans = (ans + cum[n % (p - 1)]) % p;
}

printf("%lld\n", ans);

return 0;
}

No comments

Theme images by Dizzo. Powered by Blogger.