even solution has been rejected around 5 times, I simply copy pasted the code for a try but still it wont work. Code pasted at http://paste.pocoo.org/show/273254/ please help !!
On Sat, Oct 9, 2010 at 11:36 PM, Mridul Malpani <malpanimri...@gmail.com>wrote: > @ navin :take care of conversion from double to int. > > i have submitted this solution only. > > On Oct 5, 8:59 pm, navin <navin.myhr...@gmail.com> wrote: > > @Dave k=9 only for this problem. > > > > @Mridul: > > for input > > 2 > > 19423474 8 > > 19423474 9 > > > > output: > > 16307490 26110976 > > 163074908 826110976 > > > > but actual ouptut is > > > > 16307491 26110976 > > 163074912 826110976 > > > > two digits changing > > for this only i posted my solution here. > > > > it is taken from comments section of the problem statement. > > > > i cant find where am going wrong. > > > > On Oct 5, 6:17 pm, Dave <dave_and_da...@juno.com> wrote: > > > > > @Mridul: Does it work for k = 50? > > > > > On Oct 5, 5:09 am, Mridul Malpani <malpanimri...@gmail.com> wrote: > > > > > > use log properties (mantissa) to calculate the first k digit of n^n. > > > > > > i am giving u working code, which gives answer in answer variable, > > > > > > double dummy =0; > > > > f= (double)pow(10,modf((double)n*log10((double)n),&dummy)+k-1); > > > > answer=(int)f; > > > > > > On Oct 4, 9:03 pm, navin <navin.myhr...@gmail.com> wrote: > > > > > > >http://www.codechef.com/problems/MARCHA4/ > > > > > > > for this problem i took idea from topcoder forumshttp:// > forums.topcoder.com/?module=Thread&threadID=672262&start=0&mc=... > > > > > > > and from algogeekshttp:// > www.mail-archive.com/algogeeks@googlegroups.com/msg06159.html > > > > > > > sorry that it was already discussed. > > > > > my problem is it gives me precision error. > > > > > > > input: > > > > > 11 > > > > > 4 2 > > > > > 9 3 > > > > > 999 5 > > > > > 457474575 9 > > > > > 1000000000 9 > > > > > 999999999 9 > > > > > 19 9 > > > > > 28 8 > > > > > 27 1 > > > > > 19423474 8 > > > > > 19423474 9 > > > > > > > output: > > > > > 25 56 > > > > > 387 489 > > > > > 36806 98999 > > > > > 278661176 380859375 > > > > > 100000000 000000000 > > > > > 367880063 999999999 > > > > > 197841965 589123979 > > > > > 33145523 05812736 > > > > > 4 3 > > > > > 16307491 26110976 > > > > > 163074912 826110976 > > > > > > > myouput > > > > > 25 56 > > > > > 387 489 > > > > > 36806 98999 > > > > > 278660870 380859375 > > > > > 100000000 000000000 > > > > > 367880063 999999999 > > > > > 197841965 589123979 > > > > > 33145523 05812736 > > > > > 4 3 > > > > > 16307490 26110976 > > > > > 163074908 826110976 > > > > > > > test cases taken from comments. > > > > > > > see for the last 2 test case two digits are varying. > > > > > I dont know how to correct the precision error while taking log10. > > > > > > > can you help me. > > > > > > > here follows my code. > > > > > > > #include<iostream> > > > > > #include<vector> > > > > > #include<cmath> > > > > > #include<cstring> > > > > > using namespace std; > > > > > > > long long modular_exponential(long long a, long long k, long long > mod) > > > > > { > > > > > if ( k == 1 ) > > > > > return a; > > > > > else > > > > > { > > > > > if ( k%2 == 1 ) > > > > > { > > > > > return a * modular_exponential( a , k-1 , mod ) % > > > > > mod ; > > > > > } > > > > > else > > > > > { > > > > > long long val = modular_exponential( a , k/2 , mod > ) % > > > > > mod ; > > > > > return (val*val) % mod; > > > > > } > > > > > }} > > > > > > > main() > > > > > { > > > > > int t; > > > > > cin >> t; > > > > > while ( t-- ) > > > > > { > > > > > > > long long n; > > > > > int k; > > > > > > > cin >> n >> k; > > > > > > > double v = n*log10(n); > > > > > double dummy; > > > > > //cout << "v = " << v << endl ; > > > > > double ff = modf(v,&dummy); > > > > > //cout << "ff = " << ff << endl ; > > > > > double val = pow(10.0,ff); > > > > > long long mod = 1; > > > > > for(int i = 0 ; i < k-1 ; i ++ ) > > > > > { > > > > > val = val*10; > > > > > mod = mod*10; > > > > > } > > > > > mod = mod*10; > > > > > > > cout <<(int) val << " "; > > > > > > > long long vv = modular_exponential( n , n , mod ) ; > > > > > > > if ( vv == 0 ) > > > > > { > > > > > for(int i = 0 ; i < k ; i ++ ) > > > > > { > > > > > cout <<"0"; > > > > > } > > > > > > > } > > > > > else > > > > > { > > > > > char str[100]; > > > > > sprintf(str,"%lld",vv); > > > > > > > int l = strlen(str); > > > > > > > if ( l == k ) > > > > > cout << vv; > > > > > else > > > > > { > > > > > int diff = k-l; > > > > > for(int i = 0 ; i < diff ; i ++ ) > > > > > cout << "0" ; > > > > > cout << vv ; > > > > > } > > > > > } > > > > > cout << endl ; > > > > > } > > > > > > > }- Hide quoted text - > > > > > > - Show quoted text - > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algoge...@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > > -- *GUNjan BANsal* Programming is an art of organizing complexity - Dijkstra -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algoge...@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.