SGU 113.Nearly prime numbers

水一个代码:

 

#include <iostream>
using namespace std;
int n, a; bool ok;
bool prime (int x) {
    for (int i = 2; i * i <= x; i++) if (x % i == 0) return false;
    return true;
}
int main() {
    cin >> n;
    while (n--) {
        cin >> a;
        ok = false;
        for (int i = 2; i * i <= a; i++)
            if (a % i == 0)
                if (prime (a / i) ) {
                    ok = true;
                    break;
                }
                else break;
        if (ok) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    return 0;
}

 

 
posted @ 2014-06-30 12:48  keambar  阅读(167)  评论(0编辑  收藏  举报