- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

Suppose, a person wants to buy a product of price x. But each passing day, the price of the product increases x times the price of the previous day. We have to find out the price of the product after y days since the person has made up his mind to purchase the product. If the price of the product is too much, then the answer is given as price modulo 10^9 + 7. The input is given in a list of pairs; the first value of the pair is the initial price x and the second value is y, the count of the days that have passed.

So, if the input is like nums = [(5, 2), (6, 8), (2, 12), (2722764242812953792238894584, 3486705296791319646759756475), (1505449742164712795427942455727527, 61649494321438487460747056421546274264)], then the output will be 25, 1679616, 4096, 754504594, 32955023

Here the output is 5^2 = 25, 6^8 = 1679616, 2^12 =4096, 2722764242812953792238894584^3486705296791319646759756475 = 754504594 (The value is given as value modulo 10^9 + 7), and so on.

To solve this, we will follow these steps −

- for i in range 0 to size of nums, do
- x,y := nums[i, 0], nums[i, 1]
- return the value x to the power y modulo 10^9 + 7

Let us see the following implementation to get better understanding −

def solve(nums): for i in range(len(nums)) : x,y = nums[i][0], nums[i][1] print(pow(x,y,1000000007)) solve([(5, 2),(6, 8),(2, 12) ,(2722764242812953792238894584, 3486705296791319646759756475) ,(1505449742164712795427942455727527, 61649494321438487460747056421546274264)])

[(5, 2),(6, 8),(2, 12) ,(2722764242812953792238894584, 3486705296791319646759756475) ,(1505449742164712795427942455727527, 61649494321438487460747056421546274264)]

25 1679616 4096 754504594 32955023

- Related Questions & Answers
- How to find the date after a number of days in R?
- How to find out number of days in a month in MySQL?
- Program to Find Out the Number of Squares in a Grid in Python
- Program to find out the dot product of two sparse vectors in Python
- Program to find state of prison cells after k days in python
- Python Program to find out the number of sets greater than a given value
- Java Program to find Product of unique prime factors of a number
- C/C++ Program to find the Product of unique prime factors of a number?
- Create a procedure to find out the factorial of a number?
- C/C++ Program to find Product of unique prime factors of a number?
- Python Program to find out the determinant of a given special matrix
- Python Program for Product of unique prime factors of a number
- Product of unique prime factors of a number in Python Program
- Python Program to find out the number of rooms in which a prize can be hidden
- C# Program to display the number of days in a month

Advertisements