python 编码问题
Question:
题:
A power function is that positive number that can be expressed as x^x i.e x raises to the power of x, where x is any positive number. You will be given an integer array A and you need to print if the elements of array A are Power Number or not.
一种功率函数是可以表示为x ^ X即,X加注到x的功率即正数,其中x是任意正数。 您将得到一个整数数组A,并且如果数组A的元素是否为Power Number,则需要打印。
Input:
输入:
The first line contains N, a positive integer. The next line contains N spaces – separated integers.
第一行包含N ,一个正整数。 下一行包含N个空格-分隔的整数。
3
1 3 4
Output:
输出:
For every integer print "Yes" if it’s a power number else print "No". these outputs must be separated by spaces.
对于每个整数,如果是幂数,则打印“ Yes” ,否则打印“ No” 。 这些输出必须用空格分隔。
Yes No Yes
Constraints:
限制条件:
1 <= N <= 100
1 <= A[i] <= 10^16
Explanation/Solution:
说明/解决方案:
In this question, we have to check that the given numbers in an array are power numbers or not. We will find it with the help of a power function in python. So we can do this by comparing each element with the power number so first we take input from the user and create the array of size N. then make another array that stores the power number from 1 to 14. The key focus of this question is on constraints. In this question, the constraints are given till 10^16 numbers.
在这个问题中,我们必须检查数组中给定的数字是否为幂数。 我们将在python中的幂函数的帮助下找到它。 因此,我们可以通过将每个元素与幂数进行比较来做到这一点,因此首先我们从用户那里获取输入并创建大小为N的数组。 然后制作另一个存储从1到14的幂数的数组。这个问题的重点是约束。 在这个问题中,给出的约束直到10 ^ 16个数字。
To solve this question, we are using Python3.
为了解决这个问题,我们使用Python3。
Code:
码:
# input N
N = int(input())
# input N array elements
Arr = list(map(int, input().split()))
# create another blank/empty array
Brr = []
for i in range(15):
# Append the power numbers in blank array
Brr.append(pow(i, i))
for i in range(N):
# compare the give array with
# power number array one by one
if(Arr[i] in Brr):
# if it matches print Yes other wise NO
print('Yes', end=' ')
else:
print('No', end=' ')
Output
输出量
RUN 1:
5
1 4 3 16 256
Yes Yes No No Yes
RUN 2:
5
2 4 8 16 32
No Yes No No No
翻译自: https://www.includehelp.com/python/power-challenge-competitive-coding-questions.aspx
python 编码问题