zzulioj - 2623: Small job title H

Topic links: http://acm.zzuli.edu.cn/problem.php?id=2623

Title Description
       Final exams approaching, students take an active review in the library. Today, small H also came to review the library, pulled out a small H C language textbook, found that textbooks also sandwiched a teacher out of a job title, a small H want to use this as a review of the job starts, persevering unhappy life, you can not do small H Road work to write this question, you can help write this little H Road job title it?
Known Fundamental Theorem of Arithmetic described as follows: Any. 1 a natural number greater than N, if N is not a prime number, then N can be uniquely decomposed into a finite number of prime numbers the product of N = P1a1 × P2a2 × P3a3 × ...... × Pnan, where P1 <P2 <P3 ...... <Pn are prime numbers, where ai is a positive integer index.
      Integer factorization is an important part of cryptography, and now give you an integer, let you determine whether there is a maximum power of the prime factors of an even number? E.g. 18 = 21 × 32, there is a power of prime numbers is 3 to 2.
Entry
The first input line t, represents the number (0 <t <= 1000000) input group
of 2 ~ t + 1 line, enter an integer n. (0 <n <= 1000000)
Export
If the condition that a power factor contains an even integer, output "YES" (without the quotes), and otherwise outputs "NO" (without the quotes)
Sample input  Copy
3
18
24
360
Sample output  Copy
YES
NO
YES
prompt
18 = 21 × 32 3 there is a maximum power of an even number of
24 = 23 × 31 absent the maximum power of a prime number is an even number
360 = 23 × 32 × 51 3 in the presence of the maximum power of an even number
 
That question hit the table to see at first glance thought + optimization, first screened out of prime numbers 1e6, and then we log in 1e6 of seeking the highest power of each prime factor times there is an even number,
Of course, this would certainly do so directly timeout, so we have to optimize it, in this number is divided by a prime factor later, he is certainly smaller than the original, since we are the order of play table, so
This small number of cases than the number we have already passed judgment, so the direct use on the line
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<string>
#include<vector>
#include<climits>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define max(a, b) (a > b ? a : b)
#define min(a, b) (a < b ? a : b)
#define mst(a) memset(a, 0, sizeof(a))
#define _test printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n")
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const double eps = 1e-7;
const int INF = 0x3f3f3f3f;
const ll ll_INF = 0x3f3f3f3f3f3f3f;
const int maxn = 1e6+10;
int prime[maxn];
bool ok[maxn];
void solve1() { //筛素数
    fill(prime, prime+maxn, 1);
    prime[0] = prime[1] = 0;
    int end = sqrt(maxn) + 0.5;
    for (int i = 2; i<=end; ++i)
        if (prime[i])
            for (int j = i*2; j<maxn; j+=i)
                prime[j] = 0;
}
bool solve2(int n) {
    int t = n;
    if (prime[t]) // obviously not prime 
        return  to false ;
     for ( int I = 2 ; I <= n-T &&! . 1 ; ++ I) {
         int CNT = 0 ;
         IF (Prime [I]) { // calculate the maximum power of the prime factors 
            the while ((n-%! I)) { 
                n- / = I;
                 ++ CNT; 
            } 
        } 
        IF (! ((% CNT 2 ) && CNT)) // if the maximum power of a prime factor is even, then meet the requirements 
            return  to true ;
         the else  IF (n-<t)
             return OK [n-]; // n-<t where we have counted out, so we returned directly grindstone 
    }
     return  to false ; 
} 
int main ( void ) { 
    solve1 (); 
    for ( int I = . 1 ; I <MAXN; I ++) // play table, convenience of the following O (1) Find 
        OK [I] = solve2 (I);
     int T; 
    Scanf ( " % D " , & T);
     the while (T-- ) {
         int n-; 
        Scanf ( " % D " , & n-);
        printf(ok[n] ? "YES\n" : "NO\n");
    }
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/shuitiangong/p/12078720.html