游客 Signup | Login
中文 | En

2125 - 按要求输出整数(III)

输出[N, M] (0<N<=M)范围以内既不能被3整除又不能被5整除的数.


Input

数据有多行,每一行有3个数N,M,K (0<N<=M,  0<K)。遇到一行是-1,-1, -1时,表示输入结束。

Output

输出对应[N, M]输出[N, M]范围内符合题目要求的数,并且每行只显示K个数,每个数之间用空格分隔。

每组不同范围的数据输出之间留一空行。(注意输出格式相当容易错)

Examples

Input

5 20 5
10 30 7
-1 -1 -1

Output

7 8 11 13 14
16 17 19

11 13 14 16 17 19 22
23 26 28 29

Hint

注意这道题目极容易出现格式错误!注意每行最后一个数没有空格,每组数据之间留一空行。

Solution C

# include<stdio.h>
#include<stdbool.h>
	int main(){
	    int n,m,k;
    int i;
    bool flag=true;
	    while(scanf("%d %d %d",&n,&m,&k)!=EOF){
                if(n==-1&&m==-1&&k==-1)break;
                if(!flag) printf("\n");
              bool flagtwo=true;
              int j=0;
              for(i=n;i<=m;i++){
              if((i%3!=0)&&(i%5!=0)){
                    if(!flagtwo)printf(" ");
                    printf("%d",i);
                    j++;
                    flagtwo=false;
                    if(j%k==0){
                    printf("\n");
                    flagtwo=true;
            }

        }
        if((i==m)&&(flagtwo==true)) flag=false;
        if((i==m)&&(flagtwo!=true)) {printf("\n"); flag=false;}

     }

        }
     return 0;
	}

Solution C++

#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
	int n, m, k;  
	int count;
	int flag = 0;
	while (cin>>n>>m>>k)
	{
		if (n== -1) break;
		if (flag++ != 0)
			cout<<endl;

		count = 0;
		for (int i=n; i<=m; i++)
		{			
			if (i%3 != 0 && i%5 != 0)
			{
				if (count == 0)
					cout<<i;
				else
					cout<<" " <<i;
				
				count++;
				if (count == k)
				{
					cout<<endl;
					count = 0;
				}
			}
			
		}
		if (count != 0)
			cout<<endl;
		
	}
	return 0;
}

Hint

注意这道题目极容易出现格式错误!注意每行最后一个数没有空格,每组数据之间留一空行。

Time Limit 1 second
Memory Limit 128 MB
Discuss Stats
上一题 下一题