4 条题解

  • 2
    @ 2023-3-8 16:45:16
    #include<iostream>
    using namespace std;
    bool lamp[5005]={false};
    int ans[5005];
    int main()
    {
    	int n,m;
    	cin>>n>>m;
    	for(int i=1;i<=m;i++)
    	{
    		for(int j=i;j<=n;j+=i)
    		{
    			lamp[j]=!lamp[j];//做相反操作 
    		}
    	}
    	int q=1;
    	for(int i=1;i<=n;i++)
    	{
    		if(lamp[i])
    		{
    			ans[q]=i;
    			q++;
    		}
    	}
    	for(int i=1;i<q-1;i++)
    	{
    		cout<<ans[i]<<",";
    	}
    	cout<<ans[q-1];
    	return 0;
    }
    

    考试时莫名30分555。。。

    • 1
      @ 2023-1-3 11:54:04
      #include<bits/stdc++.h>
      using namespace std;
      int n,m;
      bool qp[5005];
      int main()
      {
      	memset(qp,true,sizeof(qp));
      	cin>>n>>m;
      	for(int i=2;i<=m;i++)
      	{
      		for(int j=i;j<=n;j+=i)
      		{
      			qp[j]=!qp[j];
      		}
      	}
      	bool tag=true;
      	for(int i=1;i<=n;i++)
      	{
      		if(qp[i])
      		{
      			if(!tag)cout<<","<<i;
      			else
      			{
      				cout<<i;
      				tag=false;
      			}
      		}
      	}
      	return 0;
      }
      
      • 0
        @ 2026-4-11 18:48:51

        #include using namespace std; bool lamp[5005]={false}; int ans[5005]; int main() { int n,m; cin>>n>>m; for(int i=1;i<=m;i++) { for(int j=i;j<=n;j+=i) { lamp[j]=!lamp[j];//做相反操作 } } int q=1; for(int i=1;i<=n;i++) { if(lamp[i]) { ans[q]=i; q++; } } for(int i=1;i<q-1;i++) { cout<<ans[i]<<","; } cout<<ans[q-1]; return 0; }

        • -1
          @ 2026-4-6 13:20:41
          #include <bits/stdc++.h>
          using namespace std;
          bool a[5010];
          int main()
          {
              int n, m;
              cin >> n >> m;
              for (int i = 2; i <= m; i++)
              {
                  for (int j = i; j <= n; j += i)
                  {
                      if (a[j] == false)
                      {
                          a[j] = true;
                      }
                      else if (a[j] == true)
                      {
                          a[j] = false;
                      }
                  }
              }
              bool b = true;
              for (int i = 1;i <= n;i++)
              {
                  if (a[i] == 0)
                  {
                      if (b == 0)
                      {
                          cout << ",";
                      }
                      cout << i;
                      b = false;
                  }
              }
              return 0;
          }
          
          • 1

          信息

          ID
          922
          时间
          1000ms
          内存
          128MiB
          难度
          5
          标签
          递交数
          469
          已通过
          163
          上传者