Interprime: Xiao Ming likes to learn mathematics, and likes to do some strange problems, this day he wants to know how many M satisfy "M "N, gcd(N,M)==1, M is even". Please write a program to help Xiaoming solve this problem.

Title description

Xiao Ming likes to learn mathematics, and likes to do some strange problems. This day he wants to know how many Ms satisfy "M<N, gcd(N,M)==1, M is an even number" for a given N. Please write a program to help Xiaoming solve this problem.

Input data

The first line of input data is a positive integer T, which represents the number of groups of test data. In the next T group of test data, each group of test data is one line and contains an integer N (1≤T≤100, 1≤N≤10000).

Output Data

For each set of input data, output "Case #id: M" in a separate line, indicating that the result of the id group data is M, and id starts from 1;

Sample input

4
1
2
11
23

Sample output

Case #1: 0
Case #2: 0
Case #3: 5
Case #4: 11

Hint:

gcd(a,b)==1 means that the greatest common divisor of a and b is 1, that is, a and b are relatively prime.

Experience: Finding the greatest common divisor through division

def gcd(a, b):  #辗转相除法求最大公约数
    if b == 0:        
    	return a    
    else:        
    	return gcd(b, a%b)

T = int(input())  
for n in range(T) : 
    dArray = []      
    inputStr = input()      
    if inputStr != "":          
    	N = int(inputStr)          
    	M = 0          
    	for count in range(int((N+1)/2)-1):
    	    if gcd(N, (count+1)*2) == 1:
    	        M += 1          
    	print("Case #%d: %d" % (n + 1 , M))      
    else:
    	break  

Guess you like

Origin blog.csdn.net/tianxiefenxiang/article/details/107320421