題目鏈接 https://www.luogu.org/problemnew/show/P4325
題目描述
Given two integers A and B, A modulo B is the remainder when dividing A by B. For example, the numbers 7, 14, 27 and 38 become 1, 2, 0 and 2, modulo 3. Write a program that accepts 10 numbers as input and outputs the number of distinct numbers in the input, if the numbers are considered modulo 42.
給出10個整數,問這些整數%42後有多少個不同的餘數。 輸入
輸入包含10個小於1000的非負整數,每行一個。 輸出
輸出它們%42後,有多少個不同的餘數。 說明
第一個樣例的十個結果是1,2,3,4,5,6,7,8,9,10,有10個不同的結果;第二個樣例結果都是0,只有一個不同的結果;第三個樣例餘數是39,40,41,0,1,2,40,41,0,1,有0,1,2,39,40,41這六個不同的結果。
輸入輸出格式
輸入格式:
The input will contain 10 non-negative integers, each smaller than 1000, one per line.
輸出格式:
Output the number of distinct values when considered modulo 42 on a single line.
輸入輸出樣例
輸入樣例#1:
1
2
3
4
5
6
7
8
9
10
輸出樣例#1:
10
輸入樣例#2:
42
84
252
420
840
126
42
84
420
126
輸出樣例#2:
1
輸入樣例#3:
39
40
41
42
43
44
82
83
84
85
輸出樣例#3:
6
既然是要不同的取模結果,那就可以先得出所有餘數,放到列表num中,然後整理這個列表:使用set()去重(chóng)
參考文章https://www.cnblogs.com/chjbbs/p/5729540.html
雖然set()後順序改變,但本題對順序並無要求
所以輸出最終列表的長度即爲餘數個數
# -*- coding: utf-8 -*-
num = []
for i in range(0, 10):
n = input() #輸入整數
m = int(n)%42 #直接對輸入的整數取餘
num.append(m) #將所得餘數加入列表num中
num = list(set(num)) #使用set()除去重複
ans = len(num) #所得結果(不同的餘數)即爲去重後列表的長度
print(ans)