Untitled

 avatar
unknown
c_cpp
3 months ago
836 B
6
Indexable
//Bài 1: Kiểm tra số nguyên tố
#include <iostream>
#include <cmath>
using namespace std;

bool isPrime(long long n) {
    if (n < 2) return false;
    for (long long i = 2; i <= sqrt(n); i++) {
        if (n % i == 0) return false;
    }
    return true;
}

int main() {
    long long n;
    cin >> n;
    cout << (isPrime(n) ? "YES" : "NO");
    return 0;
}

//Bài 2: Đếm ước số
#include <iostream>
#include <cmath>
using namespace std;

int main() {
    freopen("DIVISOR.INP", "r", stdin);
    freopen("DIVISOR.OUT", "w", stdout);
    
    long long n;
    cin >> n;
    
    int count = 0;
    for (long long i = 1; i <= sqrt(n); i++) {
        if (n % i == 0) {
            count++;
            if (i != n/i) count++;
        }
    }
    
    cout << count;
    return 0;
}
Editor is loading...
Leave a Comment