Java Programming: Cutting noodles

Source: Internet
Author: User
/* A high-gluten ramen, cut in the middle, you can get 2 noodles.    If you fold 1 times in the middle, you can get 3 noodles by cutting a knife.    If you fold 2 times in a row, cut a knife in the middle, you can get 5 noodles.    so, 10 times in a row, cut a knife in the middle, how much noodles will get?    -------------------------------------------Fold 0 times, get 2, fold 1 times, get 2 * 2-1 = 3 fold 2 times, get 3 * 2-1 = 5  Fold 3 times, get 5 * 2-1 = 9 Fold 4 times, get 9 * 2-1 = 17 Fold 5 times, get 17 * 2-1 = 33 Fold 6 times, get 33 * 2-1 = 65 Fold 7 times, get 65 * 2-1 = 129 fold 8 times, get 129 * 2-1 = 257 fold 9 times, get 25 7 * 2-1 = 513 Fold 10 times, get 513 * 2-1 = 1025*/public class Test2 {public static int F (int n) {if (n==0) return 2;return 2*f (n-1) -1;} public static void Main (string[] args) {System.out.println ("10 times in Fold" +test2.f (10) + "root Slim");}}

Java Programming: Cutting noodles

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.