Skip Multiples
Python
Medium
4 views
Problem Description
Read n and k, output numbers from 1 to n but skip numbers divisible by k. Output in one line separated by spaces.
Input Format
One line: n k.
Output Format
One line numbers.
Official Solution
import sys
p=sys.stdin.read().strip().split()
if not p: sys.exit(0)
n=int(p[0]); k=int(p[1])
out=[]
for i in range(1,n+1):
if k!=0 and i%k==0:
continue
out.append(str(i))
sys.stdout.write(' '.join(out))
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!