THPTTD_67 - Số ước nguyên tố _NĐ9

Xem dạng PDF

Gửi bài giải

Điểm: 6,00 (OI)
Giới hạn thời gian: 1.0s
Giới hạn bộ nhớ: 256M
Input: UocNT.inp
Output: UocNT.out

Tác giả:
Dạng bài
Ngôn ngữ cho phép
C, C#, C++, Go, Java, JavaScript, Kotlin, Pascal, Perl, PHP, Python, Ruby, Rust, Scratch, Swift

Trong trường hợp đề bài hiển thị không chính xác, bạn có thể tải đề bài tại đây: Đề bài


Bình luận

Hãy đọc nội quy trước khi bình luận.



  • 1
    hohoanghai5042011  đã bình luận lúc 6, Tháng 4, 2024, 7:39

    include <iostream>

    include <fstream>

    include <cmath>

    using namespace std;

    bool isPrime(long long n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (long long i = 5; i * i <= n; i += 6) { if (n % i == 0 || n % (i + 2) == 0) return false; } return true; }

    int countPrimeDivisors(long long n) { int count = 0; for (long long i = 1; i <= sqrt(n); ++i) { if (n % i == 0) { if (isPrime(i)) count++; if (i != n / i && isPrime(n / i)) count++; } } return count; }

    int main() { ifstream inFile("UocNT.Inp"); ofstream outFile("UocNT.Out");

    if (!inFile.is_open() || !outFile.is_open()) {
        cerr << "Unable to open files." << endl;
        return 1;
    }
    
    long long n;
    inFile >> n;
    
    int result = countPrimeDivisors(n);
    
    outFile << result << endl;
    
    inFile.close();
    outFile.close();
    
    return 0;
    

    }