Page 1 of 1

11718 - Fantasy of a Summation

Posted: Tue Jul 13, 2010 11:24 pm
by Psh
What's the problem...
Output is okay for the test cases..
But wrong answer!!
Where's the bug ?

Help me to find it out..
Thanks in advance..


Here's my code...


#include<iostream>
#include<math.h>

using namespace std;

int main(void)
{
int t,c=1;
unsigned long long n,k,mod,w,i,sum,f,ans;
cin>>t;
while(t--)
{
cin>>n>>k>>mod;
f=(k*pow(n,k-1));
w=f%mod;
ans=0;
for(i=0; i<n; i++)
{
cin>>sum;
ans+=(sum*f%mod)%mod;
}
cout <<"Case " <<c++ <<": " <<ans <<endl;
}
return 0;
}

Re: 11718 - Fantasy of a Summation

Posted: Wed Jul 14, 2010 12:14 pm
by Jan
pow() will not work

P.S Use code tags.

Re: 11718 - Fantasy of a Summation

Posted: Tue Aug 03, 2010 4:02 am
by anis_cuet016
use repeated squaring algorithm instead of pow ........
hope it helps ....

Anis