1 1 2 2 4 2 6的n项

时间:2019-09-25 05:38:12

标签: python arrays python-2.7 term

Vaish将进一步为您提供整数N,并希望您分别打印序列空间的所有N个项。

series = [1,1,2,2,4,2,6,4,6,4,10,4,12,6,8,8,16.....,168,80,216,120,164,100]  *

输入格式 输入的第一行包括测试用例的数量T

接下来的T行由N的值组成。

约束 1 <= T <= 100

1 <= N <= 250(*此处series.count = 250)

输出格式 对于每个测试用例,请在一行中用空格分隔该系列的N个术语。

:-Sample TestCase-1
Input 
1
7

Output
1 1 2 2 4 2 6 

:-Sample TestCase-2
Input 
4
3
100
1
250

Output
1 1 2
1 1 2 2 4 2 6 32 ..... 96 42 60 40
1
1 1 2 2 4 2 6 32 ..... 168 80 216 120 164 100 

1 个答案:

答案 0 :(得分:1)

def gcd(a, b): 



    if (a == 0): 

        return b 

    return gcd(b % a, a) 


# A simple method to evaluate 
# Euler Totient Function 

def phi(n): 



    result = 1

    for i in range(2, n): 

        if (gcd(i, n) == 1): 

            result+=1

    return result 


# Driver Code 
for _ in range(int(input())):
  k = int(input())
  for n in range(1, k+1): 

    print(phi(n),end=" ")
  print()