@ navin :take care of conversion from double to int.

i have submitted this solution only.

On Oct 5, 8:59 pm, navin <[email protected]> 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 <[email protected]> wrote:
>
> > @Mridul: Does it work for k = 50?
>
> > On Oct 5, 5:09 am, Mridul Malpani <[email protected]> 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 <[email protected]> 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/[email protected]/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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to