Match Code---Do push-ups (Java) __java

Source: Internet
Author: User

Topic description
A sports school in the training gap, the teacher in order to strengthen the students ' physical fitness and for fair treatment, organized a mental plus physical training game. The rule of the game is this: the teacher let the students all n people sit in a circle. The first person first uttered the number 1. Next, sitting on his left side of the classmate to say the next number 2. The following one students from the last classmate said the number down two she used out, that is to say, 4. The next classmate to count down three, say 7. by analogy. If one of the students is wrong, he will do the same push-ups as the sum of all the numbers that the first classmate has uttered (the sum of the first student said T numbers).
to keep the numbers from getting too big, the teacher rules that when you count to k-1 in your mind, the next number starts at 0. For example, when K=13, the first few numbers the students reported were:
1, 2, 4, 7, 11, 3, 9, 3, 11, 7. The
game for a while, the first m classmate in the T said the number of times when said wrong, then he will do how many push-ups. The first row of the
input
input contains three integer n,k,t, where the meaning of N and K is as described above, T represents the number of digits that the first classmate has uttered so far.
Sample Input
3 3
Output
outputs a row that contains an integer that represents the number of push-ups that the classmate does.
Sample Output

import Java.util.Scanner;
        public class Main {public static void main (string[] args) {Scanner Scanner = new Scanner (system.in);
        int n = scanner.nextint ();
        int k = Scanner.nextint ();
        int T = Scanner.nextint ();
        Scanner.close ();
        int sum = 0;
        Boolean end = false; while (true) {for (int j = 0, num = 1, count = 0;; j +) {if (j% n = 0) {Co
                    unt++; 
                sum + = num;
                    } if (count = = T) {System.out.println (sum);
                    end = true;
                Break
            num = (num + j + 1)% K;
            } if (end) {break; }
        }

    }

}
Related Article

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.