i strongly believe that you should have tried harder . still , here goes
#include<iostream>
#include<cstdio>
#include<stdlib.h>
using namespace std;
int mulmod ( int a , int b , int c )
{
int x = 0 , y = a % c ;
while ( b > 0 )
{
if ( b % 2 == 1 )
{
x = ( x + y ) % c ;
}
y = ( y * 2 ) % c ;
b /= 2 ;
}
return x % c ;
}
int modulo ( int a , int b , int c )
{
int x = 1 , y = a ;
while ( b )
{
if ( b & 1)
{
x = mulmod ( x , y , c ) ;
}
y = mulmod ( y ,y, c ) ;
b /= 2 ;
}
return x % c ;
}
int main ()
{
printf ( "%d" , modulo ( 33554432 , 2 , 1000000000 ) ) ;
}
On Thu, Apr 14, 2011 at 9:39 PM, AAMIR KHAN <[email protected]> wrote:
>
>
> On Thu, Apr 14, 2011 at 9:08 PM, Dave <[email protected]> wrote:
>
>> @AAmir: The easiest way is to declare A as long long int. Be sure to
>> change the printf format string.
>>
>> I know that. But since i want to have only the last 9 digits of the answer
> that can be accommodated in int only so there is no need for long long i
> think.
>
>> Dave
>>
>> On Apr 14, 8:31 am, AAMIR KHAN <[email protected]> wrote:
>> > #include<cstdio>
>> > #define MOD (int)1e9
>> > using namespace std;
>> > int main() {
>> > int A = 33554432;
>> > printf("%d\n",A*A);
>> > printf("%d\n",((A*A)%MOD));
>> > return 0;
>> >
>> > }
>> >
>> > How can i calculate, lets say last 9 digits of square of 33554432 ?
>> >
>> > Thanks,
>> > Aamir
>>
>> --
>> 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.
>>
>>
> --
> 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.
>
--
Regards
Anurag Atri
II year
Computer Engineering
Delhi College Of Engineering
--
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.