Luoyoooo

与其感慨路难行,不如马上出发

[简单倍数]7-4 翻牌 (15分)

所谓翻牌,就是将原来正面朝上的牌翻过来变成背面朝上,原来背面朝上的牌翻过来变成正面朝上。

现在有 n 张扑克牌正面朝上一字排开摊在桌面上,依次编号为 1、2、、n。首先对 2 的倍数翻牌,再对 3 的倍数翻牌,接下来对 4、5、……、n 的倍数翻牌。

请问最后哪些牌正面朝上。

输入格式

扑克牌张数 n (0<n≤10000)

输出格式

正面朝上牌的编号(以空格间隔)

输入样例

6

输出样例

1 4

 

思路:跟着题目意思来,求倍数加以判断

 

 1 #include<iostream>
 2 #include<string>
 3 #include<vector>
 4 using namespace std;
 5 int main()
 6 {
 7     int n,tmp,tmp1=0;
 8     cin>>n;
 9     vector<int>a(n+1);
10     for(int i=2;i<=n;i++)
11     {
12         tmp=i;
13         for(int j=2;tmp<=n;j++)
14         {
15             
16             if(a[tmp]==0)
17                 a[tmp]=1;
18             else if(a[tmp]==1)
19                 a[tmp]=0;
20             tmp=i*j;
21         }
22     }
23         for(int i=1;i<=n;i++)
24     {
25         if(a[i]==0)
26             tmp1++;
27     }
28     for(int i=1;i<=n;i++)
29     {
30         if(a[i]==0)
31             if(tmp1!=1)
32             printf("%d ",i),tmp1--;
33             else
34             printf("%d",i);
35     }
36 }
posted @ 2020-01-19 21:58  Luoyoooo  阅读(972)  评论(0)    收藏  举报