3 条题解

  • 4
    @ 2024-11-17 18:31:44
    #include <bits/stdc++.h>
    using namespace std;
    int main(){
        int x,z,s=0;
        cin>>x;
        for(z=2;z<=x;z++){
            int k=0;
            for(int i=2;i<z;i++){
                if(z%i==0) k++;
            }
            if(k==0){
                if(x>=z){
                    x=x-z;
                    cout<<z<<endl;
                    s++;
                }
                else break;
            }
        }
        cout<<s;
    }
    

    @liveOvO (chuhaoyu) 好像不用vector也能通过"O^O"

    • 2
      @ 2024-7-30 17:50:56
      #include<bits/stdc++.h>
      using namespace std;
      bool check(int num) {
          if (num <= 1)
              return false;
          for (int i = 2; i * i <= num; ++i) {
              if (num % i == 0)
                  return false;
          }
          return true;
      }
      int main() {
          int x;
          cin >> x;
          vector<int> primes;
          int sum = 0;
          for (int i = 2; sum + i <= x; ++i) {
              if (check(i)) {
                  primes.push_back(i);
                  sum += i;
              }
          }
          for (int prime : primes) {
              cout << prime << endl;
          }
          cout << primes.size() << endl;
          return 0;
      }
      

      不用 vector 只能度过一个相对失败的人生(

      • 1
        @ 2024-8-1 16:29:36

        #include<bits/stdc++.h> using namespace std; bool check(int num) { if (num <= 1) return false; for (int i = 2; i * i <= num; ++i) { if (num % i == 0) return false; } return true; } int main() { int x; cin >> x; vector<int> primes; int sum = 0; for (int i = 2; sum + i <= x; ++i) { if (check(i)) { primes.push_back(i); sum += i; } } for (int prime : primes) { cout << prime << endl; } cout << primes.size() << endl; return 0; }

        • 1

        信息

        ID
        703
        时间
        1000ms
        内存
        256MiB
        难度
        4
        标签
        递交数
        39
        已通过
        18
        上传者