- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions

# Python Program to find out the price of a product after a number of days

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

## Example

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)])

## Input

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

## Output

25 1679616 4096 754504594 32955023

- Related Articles
- How to find the date after a number of days in R?
- Program to find out the position of a ball after n reversals in Python
- Program to find out the sum of the maximum subarray after a operation in Python
- How to find out number of days in a month in MySQL?
- Program to find state of prison cells after k days in python
- Program to Find Out the Number of Squares in a Grid in Python
- C++ Program to find out the total price
- Program to find out the dot product of two sparse vectors in Python
- Python Program to find out the number of sets greater than a given value
- Python program to find number of days between two given dates
- Program to find out the number of accepted invitations in Python
- Program to find out the number of people who get a food packet using Python
- Program to find out the number of special numbers in a given range in Python
- Program to find out the k-th largest product of elements of two arrays in Python
- Program to find out the number of pairs of equal substrings in Python