Bestcoder Round #51 (Div.2) Zball in Tina town

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 will be 11 times times bigger. On the second day, it will be 22 times times bigger. On the first NN day, it will become larger than the NN.
The original volume of Zball is 11. Tina would like to know how big the volume of Zball in the first n-1n?1 of the NN?
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 integer TT, representing the number of data groups
Next TT line, each line of a positive integer nn, meaning title surface described
T \leq 10^5,2 \leq n \leq 10^9t≤10
? 5
?? , 2≤n≤10
? 9

Output description
For each set of data, output a positive integer that represents the answer.

Input sample
2
3
10
Output sample
2
0??

This competition, can only say that the person you happy is good.
First we can first 10, we will find a rule, if n is the prime number of output n-1, if it is not a prime output 0, and when n=4, the result is 2 need a special sentence.
The problem may be that the data is too watery to see others using the most brutal method of judging primes: O (T*SQRT (n)) can also be too.
The code is as follows:

#include <iostream>#include <stdio.h>#include <queue>#include <stack>#include <algorithm>#include <string.h>#include <string>#include <math.h>using namespace STD;BOOLIsPrime (intNUM) {if(num = =2|| num = =3)    {return true; }if(num%6!=1&& num%6!=5)    {return false; } for(inti =5; I*i <= num; i + =6)    {if(num% i = =0|| Num% (i+2) ==0)        {return false; }    }return true;}intMain () {intTscanf("%d", &t); while(t--) {intNscanf("%d", &n);if(n==4)printf("2\n");Else if(IsPrime (n))printf("%d\n", N-1);Else if(!isprime (n))printf("0\n"); }}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Bestcoder Round #51 (Div.2) 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.