I'm getting WA on the question : ZSUM-SPOJ<https://www.spoj.pl/problems/ZSUM/>

Here is my code: <Let me know if you can find the problem with the code>


#include<cstdio>
#define MOD 10000007

typedef unsigned long long u64;
using namespace std;

u64 modExp(u64 x, u64 y){
    if(x==0)
        return 0;

    if(y==0)
        return 1;

    u64 z = modExp(x,y/2);

    if(y%2==0)
        return (z*z)%MOD;
    else
        return (x*z*z)%MOD;
}

int main(){
    u64 n, k; scanf("%llu%llu",&n,&k);
    while(n&&k){        
        u64 ans = 0;

        if(n>0)
            ans = (2*modExp(n-1,k) + modExp(n,k) + 2*modExp(n-1,n-1) + 
modExp(n,n))%MOD;
        
        printf("%llu\n",ans);
        scanf("%llu%llu",&n,&k);
    }

    return 0;
}

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/p6j7nmaEUb4J.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to