2 solutions

  • 2
    @ 2024-5-12 10:03:23
    #include<bits/stdc++.h>
    using namespace std;
    const int N=1010;
    bool a[N];
    int main()
    {
    	int n,m;
    	cin>>n>>m;
    	for(int i=1;i<=m;i++) //枚举人的编号 
    	{
    		for(int j=i;j<=n;j+=i) //枚举编号为i的人操作的灯的编号 
    		{
    			a[j]=!a[j]; //对编号j做相反操作	
    		}	
    	} 
    	int start=0;
    	for(int i=1;i<=n;i++)
    	{
    		if(a[i])
    		{
    			if(start!=0) cout<<","; //如果不是第一个数,需要先输出, 
    			cout<<i;
    			start++;
    		}
    	}
    	return 0;
    }
    
    • -1
      @ 2024-11-28 22:07:20
      #include<bits/stdc++.h>
      using namespace std;
      int a[11111];
      int main()
      {
          int n, m;
          cin>>n>>m;
          for(int i = 1;i <= m;i++)
          {
              for(int j = i;j <= n;j += i)
              {
                  a[j] =! a[j];
              }
          }
          int b = 0;
          for(int i = 1;i <= n;i++)
          {
              if(a[i] != 0)
              {
                  if(b != 0) cout<<",";
                  cout<<i;
                  b++;
              }
          }
          return 0;
      }
      
      
    • 1

    Information

    ID
    896
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    1
    Tags
    (None)
    # Submissions
    104
    Accepted
    41
    Uploaded By