spoj SMPDIV - Divisibility

1833 단어 #spoj
Print all integers ai such that ai is divisible by x and not divisible by y, where 1 ai < n < 100000.

Input


First, you are given t (t<100) - the number of test cases. In each of the following t lines, 3 integers: n x y.
You might assume also that x n and x is not divisible by y.

Output


In each of the following t lines, numbers requested in the problem description in the separated by a single space in ascending order.

Example


4
Input:
2 
7 2 4
35 5 12
Output:
2 6 
5 10 15 20 25 30
비교적 간단하고 코드를 직접 붙인다
import sys
debug = False

if debug:
    stdin = sys.stdin;
    fin = open('f:/oj/uva_in.txt', 'r')
    sys.stdin = fin

t = int(sys.stdin.readline())
while (t > 0):
    line = sys.stdin.readline()
    data = line.strip().split(' ')
    n = int(data[0])
    x = int(data[1])
    y = int(data[2])
    
    first = True
    for i in range(x, n, x):
        if (first):
            first = False
        else:
            print(' ', end='')
            
        if (i % y != 0):
            print(i, end='')
    print()
    
    t = t - 1
    
if debug:
    sys.stdin = stdin             
    

좋은 웹페이지 즐겨찾기