[algogeeks] [SPOJ] ZSUM

2011-10-05 Thread hashd
I'm getting WA on the question : ZSUM-SPOJhttps://www.spoj.pl/problems/ZSUM/

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


#includecstdio
#define MOD 1007

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(nk){
u64 ans = 0;

if(n0)
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.



[algogeeks] Re: informatica pattern and question of interview

2011-09-09 Thread hashd
 For question 2 I guess finding the minimum element's index should suffice 
(considering all elements are positive integer). No need to even calculate 
n! as it might cause overflow in case the arrary is big. 

-- 
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/-/esQw2UoHSI4J.
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.



Re: [algogeeks] Re: EOF

2011-09-08 Thread hashd
@Anurag: The input is said to be of unknown and large length ... read it one 
character at a time using a loop like
while((c=getchar())!=EOF){
//body
}

-- 
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/-/mxkqJD_TCgEJ.
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.