# Thread: Reducing the operation by using the modulo

1. i, I wonder that is there any way to disassemble this operation ((n+2^(n-2))^2 mod 1000000007) without counting 2^n-2. Please, help me.    2.

3. The modulo function, mod function (programming) is often mistaken for the word modify. All it simply does is continue to subtract/add a particular number to the current one until the number becomes between 0 and the determined value. In programming syntax, we could do. (GML) a=number b=boundary_number for ab a+=b until a<b and a>0 However, it must be noted that this shall only operate for a positive number. For this equation to work, there must be a loop sequence so that the equation can continue to cancel-down the value until it reaches it's target.  4. Originally Posted by Zesterer The modulo function, mod function (programming) is often mistaken for the word modify. All it simply does is continue to subtract/add a particular number to the current one until the number becomes between 0 and the determined value. In programming syntax, we could do. (GML) a=number b=boundary_number for ab a+=b until a<b and a>0 However, it must be noted that this shall only operate for a positive number. For this equation to work, there must be a loop sequence so that the equation can continue to cancel-down the value until it reaches it's target.
"mod_pow" is a function (using fast modular exponentiation) which returns the result of exponentiation modulo 1000000007 - mod_pow (the first parameter, second parameter, modulo). The first parameter is the base, and the second parameter is the exponent.
For:
y <- n + mod_pow (2, n-2, 1000000007).
result <- mod_pow (y, 2, 1000000007).

I get an incorrect result, so I had misunderstood something. Very please to explain.  5. Originally Posted by amit28it i, I wonder that is there any way to disassemble this operation ((n+2^(n-2))^2 mod 1000000007) without counting 2^n-2. Please, help me.  I'm not a hundred percent sure I understand your question, but in case you want to try and calculate this by hand, no, you don't have to calculate 2^(n-2).

First of all, (
(n+2^(n-2))^2 % 1000000007 = (n+2^(n-2)) * (n+2^(n-2)) % 1000000007
= ((n+2^(n-2)) % 1000000007) * ((n+2^(n-2)) % 1000000007) % 1000000007
= (n % 1000000007 + 2^(n-2) % 1000000007)) * (n % 1000000007 + 2^(n-2) % 1000000007)) % 1000000007

Now, what you have to do is calculate ((n % 1000000007 + 2^(n-2) % 1000000007), square that and do the modulo-operation once.
The hardest part will be calculating s = 2^(n-2) % 1000000007
s = 2^(n-2) % 1000000007
= ((2^30 % 1000000007) * 2^(n-2-30)) % 1000000007
= (73741817 * 2^(n-2-30)) % 1000000007
= (73741817 * 73741817 * 2^(n-2-30-30)) % 1000000007
etc.

HTH,
Johannes  Bookmarks
 Posting Permissions
 You may not post new threads You may not post replies You may not post attachments You may not edit your posts   BB code is On Smilies are On [IMG] code is On [VIDEO] code is On HTML code is Off Trackbacks are Off Pingbacks are Off Refbacks are On Terms of Use Agreement