简体   繁体   English

找到 a^b 的最后一位

[英]find the last digit of a^b

The problem consist in find the last digit of the potency of base a and index b.问题在于找到碱基 a 和索引 b 的效力的最后一位数字。 Given two integer numbers: the base a (0 <= a <= 20) and the index b (0 <= b <= 2,147,483,000), a and b both are not 0. Find the last digit of a^b.给定两个 integer 数:底数 a (0 <= a <= 20) 和索引 b (0 <= b <= 2,147,483,000),a 和 b 都不是 0。求 a^b 的最后一位数。

Input输入

The first line of input contains an integer t, the number of test cases (t <= 30).第一行输入包含一个 integer t,测试用例的数量(t <= 30)。 t test cases follow. t 测试用例如下。 For each test case will appear a and b separated by space.对于每个测试用例都会出现a和b,用空格隔开。

Output Output

For each test case output an integer per line representing the result.对于每个测试用例 output 和 integer 每行代表结果。

Example例子

Input: 2 3 10 6 2输入:2 3 10 6 2

Output: 9 6 Output:9 6

Here is my code in python 2这是我在 python 2 中的代码

n= int(raw_input())
for i in range(n):
    arr = map(int,raw_input().split())
    x = pow(arr[0],arr[1])
    print x%10

The problem consist in find the last digit of the potency of base a and index b.问题在于找到碱基 a 和索引 b 的效力的最后一位数字。 Given two integer numbers: the base a (0 <= a <= 20) and the index b (0 <= b <= 2,147,483,000), a and b both are not 0. Find the last digit of a^b.给定两个 integer 数:底数 a (0 <= a <= 20) 和索引 b (0 <= b <= 2,147,483,000),a 和 b 都不是 0。求 a^b 的最后一位数。

Input输入

The first line of input contains an integer t, the number of test cases (t <= 30).第一行输入包含一个 integer t,测试用例的数量(t <= 30)。 t test cases follow. t 测试用例如下。 For each test case will appear a and b separated by space.对于每个测试用例都会出现a和b,用空格隔开。

Output Output

For each test case output an integer per line representing the result.对于每个测试用例 output 和 integer 每行代表结果。

Example例子

Input: 2 3 10 6 2输入:2 3 10 6 2

Output: 9 6 Output:9 6

Here is my code in python 2这是我在 python 2 中的代码

n= int(raw_input())
for i in range(n):
    arr = map(int,raw_input().split())
    x = pow(arr[0],arr[1])
    print x%10

The problem consist in find the last digit of the potency of base a and index b.问题在于找到碱基 a 和索引 b 的效力的最后一位数字。 Given two integer numbers: the base a (0 <= a <= 20) and the index b (0 <= b <= 2,147,483,000), a and b both are not 0. Find the last digit of a^b.给定两个 integer 数:底数 a (0 <= a <= 20) 和索引 b (0 <= b <= 2,147,483,000),a 和 b 都不是 0。求 a^b 的最后一位数。

Input输入

The first line of input contains an integer t, the number of test cases (t <= 30).第一行输入包含一个 integer t,测试用例的数量(t <= 30)。 t test cases follow. t 测试用例如下。 For each test case will appear a and b separated by space.对于每个测试用例都会出现a和b,用空格隔开。

Output Output

For each test case output an integer per line representing the result.对于每个测试用例 output 和 integer 每行代表结果。

Example例子

Input: 2 3 10 6 2输入:2 3 10 6 2

Output: 9 6 Output:9 6

Here is my code in python 2这是我在 python 2 中的代码

n= int(raw_input())
for i in range(n):
    arr = map(int,raw_input().split())
    x = pow(arr[0],arr[1])
    print x%10

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM