Given 2 numbers - A and B, evaluate AB.Note:Do not use any inbuilt functions / libraries for your main logic.Input FormatThe first line of input contains T - the number of test cases. It's followed by T lines, each line containing 2 numbers - A and B, separated by space.Output FormatFor each test case, print AB, separated by new line. Since the result can be very large, print result % 1000000007Constraints30 points1 <= T <= 10000 <= A <= 1060 <= B <= 10370 points1 <= T <= 10000 <= A <= 1060 <= B <= 109ExampleInput45 21 102 3010 10Output25173741817999999937
Question
Given 2 numbers - A and B, evaluate AB.Note:Do not use any inbuilt functions / libraries for your main logic.Input FormatThe first line of input contains T - the number of test cases. It's followed by T lines, each line containing 2 numbers - A and B, separated by space.Output FormatFor each test case, print AB, separated by new line. Since the result can be very large, print result % 1000000007Constraints30 points1 <= T <= 10000 <= A <= 1060 <= B <= 10370 points1 <= T <= 10000 <= A <= 1060 <= B <= 109ExampleInput45 21 102 3010 10Output25173741817999999937
Solution
This problem is about calculating the power of a number in Python. Here is a step-by-step solution:
- First, we need to define the number of test cases, T. This can be done by using the
input()function to get user input.
T = int(input())
- Next, we need to loop through each test case. We can do this using a for loop.
for _ in range(T):
- Inside the loop, we need to get the two numbers A and B. Again, we can use the
input()function to get these numbers. Since the numbers are separated by a space, we can use thesplit()function to separate them. Then, we can convert each number to an integer using theint()function.
A, B = map(int, input().split())
- Now, we need to calculate A to the power of B. In Python, we can do this using the
**operator. However, since the result can be very large, we need to take the modulus of the result by 1000000007. This can be done using the%operator.
result = (A ** B) % 1000000007
- Finally, we need to print the result. We can do this using the
print()function.
print(result)
Here is the complete code:
T = int(input())
for _ in range(T):
A, B = map(int, input().split())
result = (A ** B) % 1000000007
print(result)
This code will calculate A to the power of B for each test case and print the result.
Similar Questions
You are given 2 numbers N & P. Print N % P.Input FormatFirst line of input contains T - number of test cases. Its followed by T lines, each line contains 2 numbers N and P, separated by space.Constraints20 points1 <= T <= 1001 <= N <= 10181 <= P <= 10880 points1 <= T <= 1001 <= N <= 10100001 <= P <= 1015Output FormatFor each test case, print the value of N % P, separated by new line.Sample Input 045 24 101085377843 817659438290826691135830692772803 95972011Sample Output 0142242058460316167
Find the cube root of the given number. Assume that all the input test cases will be a perfect cube.Note: Do not use any inbuilt functions / libraries for your main logic.Input FormatThe first line of input contains T - the number of test cases. It is followed by T lines, each containing a single integer.Output FormatFor each test case, print the cube root of the number, separated by a new line.Constraints30 points1 <= T <= 103-109 <= N <= 10970 points1 <= T <= 106-1018 <= N <= 1018ExampleInput5-27-12510006859-19683Output-3-51019-27
Understand the problem statement from the given sample input and output.Input FormatThe first line of input contains T - the number of test cases. It's followed by T lines, each line contains 2 strings A and B, separated by space, consisting only of lowercase English alphabets.Output FormatFor each test case, print the desired output, separated by a new line.Constraints10 points1 <= T <= 1001 <= len(A), len(B) <= 10040 points1 <= T <= 10001 <= len(A) <= 50001 <= len(A), len(B) <= 5000ExampleInput2data structuressmart interviewsOutputsrucuresineview
You are given an array of integers. For each element in the array, find the number of smaller elements on the right side and print the total count.Input FormatThe first line of input contains T - the number of test cases. It's followed by 2T lines, the first line contains N - the size of the array. The second line contains the elements of the array.Output FormatFor each test case, print the sum of count of smaller elements on right side of each element in the array, separated by new line.Constraints30 points1 <= N <= 10370 points1 <= N <= 105General Constraints1 <= T <= 100-104 <= A[i] <= 104ExampleInput254 10 54 11 8615 35 25 10 15 12Output410ExplanationTest Case 1Smaller Elements on right side of 4 : 0Smaller Elements on right side of 10 : 1Smaller Elements on right side of 54 : 2Smaller Elements on right side of 11 : 1Smaller Elements on right side of 8 : 0Total Count = 0 + 1 + 2 + 1 + 0 = 4Test Case 2Smaller Elements on right side of 15 : 2Smaller Elements on right side of 35 : 4Smaller Elements on right side of 25 : 3Smaller Elements on right side of 10 : 0Smaller Elements on right side of 15 : 1Smaller Elements on right side of 12 : 0Total Count = 2 + 4 + 3 + 0 + 1 + 0 = 10
Given 2 numbers, find their LCM and HCF.Note: Do not use any inbuilt functions/libraries for your main logic.Input FormatFirst line of input contains T - number of test cases. Its followed by T lines, each contains 2 numbers A and B.Constraints1 <= T <= 1051 <= A,B <= 109Output FormatFor each test case, print their LCM and HCF separated by space, separated by newline.Sample Input 044 71013 16 4605904 996510762Sample Output 01420 213 112 27740895599216 78
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.