5 条题解

  • 1
    @ 2024-3-17 15:08:52

    这道问题是累加问题,很简单,直接开做

    #include <iostream>
    using namespace std;
    int main()
    {
        int n, sum = 0;
        cin >> n;
        for (int i = 1; i <= n; i++)
        {
            int num = 0;
            if (i % 2 == 0)
            {
                num++;
            }
            if (i % 3 == 0)
            {
                num++;
            }
            if (i % 5 == 0)
            {
                num++;
            }
            if (i % 7 == 0)
            {
                num++;
            }
            if (num >= 2)
            {
                sum += i;
            }
        }
        cout << sum;
        return 0;
    }
    
    • 1
      @ 2023-10-29 16:37:15

      代码如下:

      #include <iostream>
      using namespace std;
      int main()
      {
          int n,c,k=0;
          cin >> n;
          for (int i=1;i<=n;i++)
          {
              c=0;
              if (i%2==0)
              {
                  c++;
              }
              if (i%3==0)
              {
                  c++;
              }
              if (i%5==0)
              {
                  c++;
              }
              if (i%7==0)
              {
                  c++;
              }
              if (c>=2)
              {
                  k+=i;
              }
          }
          cout << k;
          return 0;
      }
      

      还有,这道题和【入门】能被2、3、5、7中至少2个数整数的数类似,建议先去看看

      • 1
        @ 2023-4-28 7:12:52
        #include<bits/stdc++.h>
        using namespace std;
        int main()
        {
            int n,ans=0;
            cin>>n;
            for (int i=1;i<=n;i++)
                if ((i%2==0&&i%3==0)||(i%2==0&&i%5==0)||(i%2==0&&i%7==0)||(i%3==0&&i%5==0)||(i%3==0&&i%7==0)||(i%5==0&&i%7==0))
                    ans+=i;
            cout<<ans;
            return 0;
        }
        • 1
          @ 2023-2-19 20:54:25
          #include <bits/stdc++.h>
          using namespace std;
          int main()
          {
          	int n, i, c, s = 0;
          	cin >> n;
          	for (i = 1; i <= n; i++)
              {
          		c = 0;
          		if (i % 2 == 0)
          			c++;
          		if (i % 3 == 0)
          			c++;
          		if(i % 5 == 0)
          			c++;
          		if(i % 7 == 0)
          			c++;
          		if(c >= 2)
          			s += i;
          	}
          	cout << s;
              return 0;
          }
          
          • 0
            @ 2023-8-19 19:55:34

            半夜打卡第5题

            #include <bits/stdc++.h>
            using namespace std;
            int a , x , s;
            int main()
            {
                cin >> a;
                for (int i = 1;i <= a;i++)
                {
                    if (i % 2 == 0) x++;
                    if (i % 3 == 0) x++;
                    if (i % 5 == 0) x++;
                    if (i % 7 == 0) x++;
                    if (x >= 2) s += i;
                    x = 0;
                }
                cout << s;
                return 0;
            }
            
            • 1

            【入门】求满足条件的数的和

            信息

            ID
            446
            时间
            1000ms
            内存
            32MiB
            难度
            1
            标签
            递交数
            85
            已通过
            59
            上传者