- #1
paut
- 7
- 0
Hi, 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.
paut said:"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.
Evaluations of (n + 2^(n-2))^2 mod 1000000007, for n = ...
2: 9 9 9
3: 25 25 25
4: 64 64 64
10: 70756 70756 70756
20: 729962420 729962420 729962420
456: 781936176 781936176 781936176
456000: 832296930 832296930 832296930
4560000: 786542175 786542175 786542175
45600000: 98463981 98463981 98463981
456000000: 494805060 494805060 494805060
500000005: 250000008 250000008 250000008
1000000008: 4 4 4
paut said:Here are the calculations that should be correct: http://img695.imageshack.us/img695/3950/calcw.png
My program returns the same result (the first based on a string and second without them). I also have exactly the same results as you. The problem is probably in the wrong set formula :/ I see no other option :/
Thank you very much for your help which was given to me here ;)
paut said:I send the source code for online judge, that evaluates the results, but the score for my program is "Wrong answer".
The modulo operation, denoted by the % symbol, calculates the remainder after dividing one number by another. For example, 10 % 3 would result in a remainder of 1, as 10 divided by 3 is 3 with a remainder of 1. This operation is commonly used in programming to determine whether a number is even or odd, or to cycle through a set of values.
The modulo operation can be used to reduce operations by limiting the range of values that need to be calculated. For example, instead of calculating the sum of all numbers from 1 to 100, we can use the modulo operation to determine the sum of all odd numbers from 1 to 100, which would require fewer operations.
Reducing operations using the modulo operation can save time and resources, as it eliminates the need for unnecessary calculations. This can be especially useful when dealing with large numbers or complex algorithms. It can also improve the efficiency and speed of a program.
Yes, there are some limitations to using the modulo operation. One limitation is that it can only be used with integers, not decimals or fractions. Additionally, it may not be suitable for all types of calculations and may not always result in a significant reduction in operations.
Most programming languages have a modulo operator, but the syntax may vary. Some languages use the % symbol, while others use the keyword "mod". It is important to check the documentation of the specific language you are using to ensure the correct usage of the modulo operation.