Zball in Tina town (prime)

Source: Internet
Author: User

Zball in Tina townaccepts:397submissions:2463Time limit:3000/1500 MS (java/others)Memory limit:262144/262144 K (java/others) Problem Description

Tina 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 becomes 11 Time as large as its original size. On the second day,it'll become 22 Times as large as the size on the first day. On the n-th day,it'll become nn 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.

Input

The first line of input contains an integer tt, representing the number of CA Ses.

The following tt Lines, each line contains an integer nn , according to the description.T \leq {10}^{5},2 \leq n \leq {10}^{9}T≤ 10? 5 ??,2≤N≤ 10? 9 ??

Output

For each test case, the output of an integer representing the answer.

Sample Input
2310
Sample Output
20
Test instructions
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 Times. On the second day, it gets bigger. 22 Times. In section nn Days, it gets bigger. nn Times. Zball the original volume is 11 。 Tina would like to know that Zball in the first n-1 n? 1  The volume of the day nn How big is the modulus? Tina is a stupid girl, of course not, so she asked you to help her figure out the answer.
      Idea: Because (n-1) in addition to 4 of any non-prime number can be combined with less than his combination of multiplication, so all 0, if it is a prime number of words because there is no less than his other numbers multiplied to get, so (n-1)%n = = n-1   , direct output n-1
If n equals 4, direct output 2
 
#include <iostream> #include <algorithm> #include <stdio.h> #include <string.h> #include < string.h> #include <stdlib.h> #include <math.h>using namespace Std;int n;int flag;int main () {    int T;    scanf ("%d", &t);    while (t--)    {        flag = 0;        scanf ("%d", &n);        if (n = = 4)        {            printf ("2\n");            Continue;        }        int m = sqrt (n-1);        for (int i=2;i<=m;i++)        {            if (n%i = = 0)            {                flag = 1;                break;            }        }        if (flag = = 0)        {            printf ("%d\n", n-1);        }        else        {            printf ("0\n");        }    }    return 0;}


Copyright NOTICE: This article is the original blogger article, if you have special needs, please contact Bo Master qq:793977586.

Zball in Tina town (prime)

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.