Question

In: Computer Science

Given a number represented exponentially, calculate it's value. The number might be very large so print...

Given a number represented exponentially, calculate it's value.
The number might be very large so print out its value mod 91.

Input Format

First line is the number (n) of exponentials you will have to calculate.
The next n lines will each contain two values (b and e), the base value and the exponent.

Constraints

All input values will be valid java integers. n will be > 0
b will be > 0 and <= 10000
e will be >= 0

Output Format

Output n values, the solutions for each of the n exponents you are given.

Sample Input 0

3
13 3
76 3
100 3
Sample Output 0

13
83
1
Explanation 0

13^3 = 13 * 13 * 13 = 2197
2197 mod 91 = 13
76^3 = 76 * 76 * 76 = 483,976
483,976 mod 91 = 83
100^3 = 100 * 100 * 100 = 1,000,000
1,000,000 mod 91 = 1

Sample Input 1

6
90 3
66 3
90 3
80 4
28 4
90 4
Sample Output 1

90
27
90
81
42
1

Solutions

Expert Solution

Program Code Screenshot :

Sample Output :

Program Code to Copy

import java.util.Scanner;

class Main{

    static int pow(int b, int e, int m){
        //If exponent is 0, return 1
        if(e==0){
            return 1;
        }
        //Find b^(e/2)
        int ans = pow(b,e/2,m);
        ans = (ans*ans)%m;
        //Deal with odd exponent
        if(e%2==1){
            ans = (ans*b)%m;
        }
        return ans;
    }

    public static void main(String[] args) {
        //Scanner to read user input
        Scanner obj = new Scanner(System.in);
        int n = obj.nextInt();
        //Read all base and exponent and print results
        for(int i=0;i<n;i++){
            int b = obj.nextInt();
            int e = obj.nextInt();
            System.out.println(pow(b,e,91));

        }
    }
}

Related Solutions

3. Karen runs a print shop that makes posters for large companies. It is a very...
3. Karen runs a print shop that makes posters for large companies. It is a very competitive business. The market price is currently $1 per poster. She has fixed costs of $250. Her variable costs are $1,000 for the first thousand posters, $800 for the second thousand, and then $750 for each additional thousand posters. What is her AFC per poster (not per thousand!) if she prints 1,000 posters? 2,000? 10,000? What is her ATC per poster if she prints...
Karen runs a print shop that makes posters for large companies. It is a very competitive...
Karen runs a print shop that makes posters for large companies. It is a very competitive business. The market price is currently $1 per poster. She has fixed costs of $250. Her variable costs are $2,000 for the first thousand posters, $1,600 for the second thousand, and then $1,000 for each additional thousand posters. Instructions: Round your answers to 3 decimal places. a. What is her AFC per poster (not per thousand!) if she prints 1,000 posters? 2,000? 10,000? b....
Karen runs a print shop that makes posters for large companies. It is a very competitive...
Karen runs a print shop that makes posters for large companies. It is a very competitive business. The market price is currently $1 per poster. She has fixed costs of $250. Her variable costs are $1,800 for the first thousand posters, $1,500 for the second thousand, and then $900 for each additional thousand posters. Instructions: Round your answers to 3 decimal places. a. What is her AFC per poster (not per thousand!) if she prints 1,000 posters?      What if...
Historically, the structure of retailing in India was very fragmented with a large number of very...
Historically, the structure of retailing in India was very fragmented with a large number of very small stores serving most of the market. Supply chains were also very poorly developed and fragmented. As recently as 2010, larger format big box stores, chain stores, and supermarkets only accounted for 4 percent of retail sales in the country (compared to 85 percent in the United States). This might sound like an ideal opportunity for efficient foreign retailers such as Walmart, IKEA, Tesco,...
Historically, the structure of retailing in India was very fragmented with a large number of very...
Historically, the structure of retailing in India was very fragmented with a large number of very small stores serving most of the market. Supply chains were also very poorly developed and fragmented. As recently as 2010, larger format big box stores, chain stores, and supermarkets only accounted for 4 percent of retail sales in the country (compared to 85 percent in the United States). This might sound like an ideal opportunity for efficient foreign retailers such as Walmart, IKEA, Tesco,...
Historically, the structure of retailing in India was very fragmented with a large number of very...
Historically, the structure of retailing in India was very fragmented with a large number of very small stores serving most of the market. Supply chains were also very poorly developed and fragmented. As recently as 2010, larger format big box stores, chain stores, and supermarkets only accounted for 4 percent of retail sales in the country (compared to 85 percent in the United States). This might sound like an ideal opportunity for efficient foreign retailers such as Walmart, IKEA, Tesco,...
Historically, the structure of retailing in India was very fragmented with a large number of very...
Historically, the structure of retailing in India was very fragmented with a large number of very small stores serving most of the market. Supply chains were also very poorly developed and fragmented. As recently as 2010, larger format big box stores, chain stores, and supermarkets only accounted for 4 percent of retail sales in the country (compared to 85 percent in the United States). This might sound like an ideal opportunity for efficient foreign retailers such as Walmart, IKEA, Tesco,...
The economic environment in which businesses operate is obviously very important. So, it's no surprise that...
The economic environment in which businesses operate is obviously very important. So, it's no surprise that throughout history, philosophers and economists have proposed different ways to structure an economy. One way to think about these different systems it to imagine a spectrum between pure capitalism and free markets on one end and communism or so-called command economies on the other end. What role should the government play in an economy? 1.What role should the government play in an economy? 2....
It's been a while since I've done this type of chemistry so I'm just very lost...
It's been a while since I've done this type of chemistry so I'm just very lost trying to figure out these problems. Could someone please help and if you could write out the equations or give an explanation as to how you came up with your answers. Thank you in advance! 1. You have 50 mL of a buffer solution that is 0.15 M in HA and 0.25 M in A-. Calculate the pH of the solution after you add...
(C++) Follow the template given to calculate and print the monthly salary of an employee. We...
(C++) Follow the template given to calculate and print the monthly salary of an employee. We assume the employee works for 50 weeks during the year with an hourly rate of $25. Your program should ask the user the workHoursPerWeek. If it's over 40, then the excess hours (i.e., workHoursPerWeek over 40) are paid with 20% overtime rate. Note: just print out the monthly salary. Example: If I work for 45 hours with a rate of $30/hr, then my weekly...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT