1 solutions

  • 0
    @ 2026-11-15 12:38:05

    C++ :

    #include <bits/stdc++.h>
    using namespace std;
    bool is_prime(int val){
        int m = sqrt(val + 0.5);
        for(int i = 2; i <= m; i++){
            if(val % i == 0){
                return false;
            }
        }
        return true;
    }    
    int main()
    {
        int n;
        cin>>n;                    
        for(int j = n + 1; ; j++){
            if(is_prime(j)){
                cout<<j<<" ";
                break;
            }
        }
        for(int j = n - 1; j >= 2; j--){
            if(is_prime(j)){
                cout<<j<<endl;
                break;
            }
        }
        return 0;
    }
    
    • 1

    Information

    ID
    184
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    (None)
    Tags
    # Submissions
    0
    Accepted
    0
    Uploaded By