Hrbust1328 equal least common multiple (sieve prime number, prime factor decomposition)

Source: Internet
Author: User

 

Question:

Determine whether An AND An-1 are equal.

N is divided into two situations --

1. n is a prime number,

2. n is the sum.

= It seems like a piece of nonsense .. When a prime number is used, no can be directly output, because the prime number cannot be equal to An-1. If n is the power of a ^ B when the number is combined, it is also NO. The reason is very simple. The minimum public factor of n in the previous number cannot exceed the power of n.

 

 

// ================================================ ==================================================================== // Name: number theory problems. cpp // Author: // Version: // Copyright: Your copyright notice // Description: Hello World in C ++, ansi-style // ========================================== ========================================================== = # include
 
  
# Include
  
   
# Include
   
    
Using namespace std; # define lln long int # define MAXN 1000001 bool vis [MAXN]; int prime [100000]; int p; void Prime () {// 0 is not a combination, 1 is a combination of memset (vis, 1, sizeof (vis); p = 0; int I, j; for (I = 2; I <MAXN; I ++) {if (vis [I]) {prime [p ++] = I; for (j = 2 * I; j <MAXN; j + = I) vis [j] = 0;} else continue;} void ace () {// initPrime (); // work pointint t, I; // numint a; int num; cin> t; while (t --) {scanf (% d, & a); if (a = 2) {printf (NO); continue;} if (vis [a]) printf (NO); else {num = 0; for (I = 0; I <= p; I ++) {if (a % prime [I] = 0) {num ++; while (a % prime [I] = 0) a/= prime [I];} if (a = 1) break;} if (num> = 2) printf (YES); else printf (NO );}}} int main () {ace (); return 0 ;}
   
  
 


 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.