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

View as PDF

Submit solution

Points: 6.00 (partial)
Time limit: 1.0s
Memory limit: 256M
Input: UocNT.inp
Output: UocNT.out

Author:
Problem type
Allowed languages
C, C#, C++, Go, Java, JavaScript, Kotlin, Pascal, Perl, PHP, Python, Ruby, Rust, Scratch, Swift

In case the statement didn't load correctly, you can download the statement here: Statement


Comments

Please read the guidelines before commenting.



  • 1
    hohoanghai5042011  commented on April 6, 2024, 7:39 a.m.

    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;
    

    }