9 degree tutorial 89th questions

Source: Internet
Author: User

C language source code: [cpp] # include <stdio. h> # include <math. h> int s [18]; int mark [18]; int pri (int n) {int I, B; B = (int) sqrt (n) + 1; if (n = 2) return 1; I = 2; while (I <= B) {if (n % I = 0) return 0; else I ++ ;} return 1;} void input (int I, int n) {int j, flag; if (I = n + 1) {flag = 0; for (j = 1; j <n; j ++) {if (pri (s [j] + s [j + 1]) = 0) {flag = 1; break ;}} if (pri (s [1] + s [n]) = 0) flag = 1; if (flag = 0) {for (j = 1; j <n; j ++) printf ("% d", s [j]); Printf ("% d \ n", s [j]) ;}} else {for (j = 1; j <= n; j ++) {if (mark [j] =-1 & pri (s [I-1] + j) = 1) {s [I] = j; mark [j] = 1; input (I + 1, n); mark [j] =-1 ;}}} int main () {int n, num, I; num = 1; s [1] = 1; while (scanf ("% d", & n )! = EOF) {for (I = 0; I <= n; I ++) mark [I] =-1; mark [1] = 1; printf ("Case % d: \ n", num ++); input (2, n); printf ("\ n") ;}} share to: Previous: 9 degree tutorial 88th question next: 9 degree tutorial 90th question

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.