HDU-5391 Zball in Tina town

Source: Internet
Author: User

(n-1)!/n is that if n is a prime number, it is equal to N-1else to 0.

List of primes:

Zball in Tina town

Time limit:3000/1500 MS (java/others) Memory limit:262144/262144 K (java/others)
Total submission (s): 833 Accepted Submission (s): 477


Problem Descriptiontina Town was a friendly place. People there care on each of the other.

Tina has a ball called Zball. Zball is magic. It grows larger every day. On the first day, it becomes1Time as large as its original size. On the second day,it'll become2 times as large as the size on the first day. On the n-th day,it would become n times as large as the size on the (n-1)-th Day. Tina want to know it size on the (n-1)-th day modulo n.

Inputthe first line of input contains an integerT , representing the number of cases.

The followingT Lines, each line contains an integerN, according to the description.
T≤5,2≤n≤9

Outputfor each test case, output an integer representing the answer.

Sample Input2310

Sample Output20

Source
#include <iostream>#include<cstdio>#include<cstring>using namespacestd;BOOLIs_prime (intN) {     for(intI=2; i*i<=n;i++){         if(n%i==0)return false; }    returnn!=1;}intMain (void){intn,t;scanf ("%d",&t);  while(t--) {scanf ("%d",&N); if(n==4) {printf ("2\n"); Continue; }        if(Is_prime (n)) printf ("%d\n", N-1); Elseprintf ("0\n"); }    return 0;}

HDU-5391 Zball in Tina town

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.