C-The story of the Fox and the Rabbit

Source: Internet
Author: User

Title Description

Around the top of the mountain there are 10 holes, a fox and a rabbit each live a hole. The fox always wants to eat rabbits. One day the rabbit said to the Fox: "You want to eat I have a condition, first the hole from the 1~10 number, you start from hole 10th, first to 1th hole looking for me, the second time 1 holes to find me, the third time 2 holes to find me, and so on, and so on. If you can find me, you can have a hearty meal. But I can't stop until I find me. "The fox is full of promise to start looking for, it from morning to night to find n times hole, tired faint past also did not find rabbits." Excuse me, which hole did the fox faint in? What holes can the child hide in?

Input

Enter a positive integer N (1<=n<=1000)

Output

First line: Output the number of holes the rabbit can hide in
Second line: The number of the hole where the fox fainted

Sample input
3
Sample output
2 4 5 7 8 9 10
6

1 /************2 variable definition:3 N: Find the N-th hole altogether4 K: K-Find Hole (1<= k <=n)5 6 find_rabbit: Returns the numbered of the hole found in the K-th. 7 8 **********/9#include <stdio.h>Ten intFind_rabbit (intk) { One     if(k==1){ A         return 1;/*first time in hole 1th,*/ -}Else{ -         if(Find_rabbit (K-1) + k)%Ten==0){ the             return Ten; -}Else{ -             return(Find_rabbit (K-1) + k)%Ten; -         } +     } - } + voidMain () { A     inti,holes[Ten]; at     intn= -; -      for(i=0; i<Ten; i++){ -Holes[i] =1;/*initialized to 1, 1 for the Fox has not been to the hole*/ -     } -      -      for(i=1; i<=n; i++){ inHoles[find_rabbit (i)-1] =0;/*eg: the first time in hole 1th, that is holes[0] is set to 0, use index to reduce 1, 0 for the fox to the hole*/ -     } to  +      for(i=0; i<Ten; i++){ -         if(Holes[i] = =1){ theprintf"%d", i+1);/*because I is starting from 0, so add 1*/ *         } $     }Panax Notoginsengprintf"\n%d \ n", Find_rabbit (n)); -  the      +}

C-The story of the Fox and the Rabbit

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.