dùng hàm đảo nguọc ạ ngôn ngữ c++ ạ

Report
Question

Please briefly explain why you feel this question should be reported.

Report
Cancel

dùng hàm đảo nguọc ạ
ngôn ngữ c++ ạ

Answers ( 1 )

  1. Please briefly explain why you feel this answer should be reported.

    Report
    Cancel

    câu 1:

    #include <iostream>
    using namespace std;
    int main() {
        int a,b;
        cin >> a >> b;
        if (a%2==0) a++;
        int s=0;
        for (int i=a; i<=b; i+=2) {
            s+=i;
        }
        cout << s;
    }

    câu 2:

    #include <iostream>
    #include <vector>
    using namespace std;
    vector<bool> primes(100001, true);
    void sang() {
        primes[0] = primes[1] = false;
        for (int i=2; i*i<=100000; i++) {
            if (primes[i]) {
                for (int j=i*i; j<=100000; j+=i) {
                    primes[j] = false;
                }
            }
        }
    }

    int sum(int n) {
        int s=0;
        while (n) {
            s+=n%10;
            n/=10;
        }
        return s;
    }

    int main() {
        sang();

        int n;
        cin >> n;
        bool check = true;
        for (int i=11; i<=n; i++) {
            if (primes[i]) {
                if (primes[sum(i)]) {
                    cout << i << ” “;
                    check = false;
                }
            }
        }
        if (check) cout << 0;
    }

Leave an answer

Browse

By answering, you agree to the Terms of Service and Privacy Policy.