HDU 5391 Zball in the town of Tina (playing the watch pattern)

Source: Internet
Author: User

Problem Description
Tina town is a kind and friendly place where everyone cares about each other. Tina has a ball whose name is Zball. Zball is amazing, it gets bigger every day. On the first day, it gets bigger.11 time times. On the second day, it gets bigger.2Twice times. In sectionNN days, it gets bigger.N n times 。 Zball Original volume is 11. Tina would like to know that zball in n-1 n − 1 days of volume to n n How big is the mold? ? Tina is a stupid girl, of course not, so she asked you to help her figure out the answer.  
Enter a description
First line a positive integerTT, which indicates the number of data groups nextTT line, one positive integer per lineNN, the meaning of the title surface is describedT \leq 10^5,2 \leq n \leq 10^9T ≤105,2≤n≤< Span class= "Mord" >10? 9            
Output Description
For each set of data, output a positive integer that represents the answer.
Input Sample
2310
Output Sample
20

this question is to beg   (n-1)! MoD n (n−< Span class= "Mord" >1) !   mo d   n

if nn for composite, obviously the answer is 0.

if nn for prime numbers, then the answer from Wilson's theorem is  n-1 < Span class= "Mord mathit" >n−1

Note that there is a trick for  n< Span class= "katex-html" >< Span class= "Mord mathit" >n = 4

Just make a watch and find the rules.

1#include <iostream>2#include <cstdio>3#include <cstring>4#include <vector>5#include <Set>6#include <map>7#include <cmath>8#include <stdlib.h>9 using namespacestd;Ten intN; One  A  - intMain () - { the     intT; -scanf"%d",&t); -      while(t--) -     { +scanf"%d",&n); -          +         if(n==4) A         { atprintf"2\n"); -             Continue; -         } -         intflag=0; -          for(intI=2; i*i<=n;i++) -         { in             if(n%i==0) -             { toflag=1; +                  Break; -             } the         } *         if(flag==0) $printf"%d\n", N-1);Panax Notoginseng           Else  -printf"0\n"); the     } +      A     return 0; the}
View Code

HDU 5391 Zball in the town of Tina (playing the watch pattern)

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.