The power of the Noj network game c stunt

Source: Internet
Author: User

Topic:

Power of stunts time limit (normal/java) : ms/3000 MS Run memory limit: 65536 KByte
Total submissions: 485 tested by: 106

Title Description

Power operation is one of the common mathematical operations, its principle is multiplied by the same number of times, but sometimes when the power exponent is particularly large, such an operation is too waste of time. Please learn to add special effects to power, so as to increase the efficiency of power operation to an acceptable degree.



Input

first row an integer T t

x Span style= "Box-sizing:border-box; Font-family: the song body; >, Y  ask x y 2 ≤ x, Y ≤10^9)

Output

Each set of data outputs an integer that represents the result of a power operation on the 1000000007 modulo

Sample input

2
2 4
2 100000000

Sample output

16
494499948

Source of the topic

Kojimai



Topic Analysis:

I understand this problem as "naked fast power" (do not know whether the correct understanding of the idea of the author, the following code for reference only). Originally want to Rob FB, but has not dared to hand, since the time also because of the data of the long long WA once.


The code is as follows:

/* * a.cpp * *  Created on:2015 March 29 *      author:administrator * * #include <iostream> #include <cstdio>u Sing namespace Std;long long Quickpow (Long long m, long long N, long long K) {long long B = 1;while (n > 0) {if (n & ; 1) {b = (b * m)% K;} n = n >> 1;m = (M * m)% K;} return b;} int main () {int t;scanf ("%d", &t), long long AA = 1000000007ll;while (t--) {Long Long A, b;scanf ("%i64d%i64d", &a, &B);p rintf ("%i64d\n", Quickpow (A, B, AA));} return 0;}






The power of the Noj network game c stunt

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.