// One-star problem // Problem UVA406 Prime Cuts /* This program is written by Prof. Chua-Huang Huang Department of Information Engineering and Computer Science Feng Chia University Taichung, Taiwan Disclaimer: The programming problem is downloaded from UVa Online Judge (https://uva.onlinejudge.org/). The program solution is provided for helping students to prepare Collegiate Programming Examination (CPE). The author does not guarantee the program is completely correct to pass UVa Online Judge platform or CPE examination platform. This program is not intended for a student to copy only. He/She should practice the programming problem himself/herself. Only use the program solution as a reference. The author is not responsible if the program causes any damage of your computer or personal properties. No commercial use of this program is allowed without the author's written permission. */ #include #include #include int main(void) { int primes[1000]; // Prime list, n is between 1 and 1000 int n, C; int i, j, upper, count; while (scanf("%d %d", &n , &C)==2) { // Input n and C. count = 0; // Set prime list count to 0. // Construct prime list between 1 and n. for (i=1; i<=n; i++) { // Check all numbers between 1 and n. upper = sqrt(i); // Set the upper bound of prime numbers to be checked. for (j=upper; j>1; j--) if (i%j==0) break; // Find a number divides i. if (j==1) { // In this case, i is a prime number. primes[count++] = i; // Insert i to the prime list and increment prime count. } } printf("%u %u: ", n, C); // Print n and C. if (count%2==0 && count>=C*2) // Even length and count>=C*2. for (i=0; i=C*2-1) // Odd length and count>=C*2-1 for (i=0; i