ACM hdu2442 ACM (array complicated manipulation)

Source: Internet
Author: User
Http://acm.hdu.edu.cn/showproblem.php? PID = 2441acm (array complicated manipulation)

Time Limit: 5000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 258 accepted submission (s): 60

Problem descriptiongiven an infinite array of integers 2, 3,... now do some operations on it.

The operation is to choose a minimum number from the array which is never been chosen, then change the status of its multiples excluding itself, I. E remove the multiples of the chosen number if they are in the array, otherwise add it to the array. keep the order after change.

For instance, the first step, choose number 2, change the status of 4, 6, 8, 10... they are all removed from the array. the second step, choose 3, change the status of 6, 9, 12, 15...

Pay attention: 9 and 15 are removed from the array while 6 and 12 are added to the array.

Inputevery line contains an integer n. The zero value for N indicates the end of input.

Outputprint "yes" or "no" According whether N is in the array.

Sample input2
30
90
0

Sample outputyes
Yes
No

Hint

The number N never has a prime factor greater than 13000000, but N may be extremely large.

 

Source2008 Asia Harbin Regional Contest online

Recommendgaojie http://www.cnblogs.com/main/archive/2009/05/21/1486322.htmlhttp://hi.baidu.com/5l2_/blog/item/8c1e51dcb72511a7cd11662b.htmlhttp://hi.baidu.com/54xiaoke/blog/item/12ed933f9d8b11c47d1e71ef.html
# Include <stdio. h> # include <iostream> # include <math. h> # include <string. h> using namespace STD; # define Max 65536 char STR [1000]; // create a table to generate all the prime numbers of Max. // use the Limit Method int prime [Max]; int vext () {bool num [Max + 1]; int I, j, Len; Double T = SQRT (double) max); memset (Num, 1, sizeof (Num )); // be careful when initializing memset. Here it is of the bool type. If it is not 0, it is true for (I = 2; I <t; I ++) {If (Num [I]) {for (j = 2; I * j <Max; j ++) num [I * j] = 0 ;}} Len = 0; for (I = 2; I <Max; I ++) if (Num [I]) prime [le N ++] = I; // Len records the return LEN Length of the total prime number;} // division with high precision to determine whether P is divisible by N bool Div (char * P, int N) {char temp [1000]; int I, sum = 0, Len = 0; for (I = 0; P [I]! = 0; I ++) {sum = sum * 10 + P [I]-'0'; temp [Len ++] = sum/n + '0 '; sum % = N;} temp [Len] = 0; If (sum = 0) {for (I = 0; temp [I] = '0 '; I ++); strcpy (p, temp + I); return 1;} else return 0;} int main () {int I, j, Len; len = vext (); While (scanf ("% s", STR), strcmp (STR, "0 ")! = 0) {If (strcmp (STR, "1") = 0) {printf ("NO \ n"); continue;} int count; for (I = 0; I <Len; I ++) {COUNT = 0; while (Div (STR, prime [I]) {count ++; If (count> = 2) break ;} if (count> = 2) break;} If (count> = 2) printf ("NO \ n"); else printf ("Yes \ n ");} return 0 ;}

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.