HDU 5391 Zball in Tina town

Source: Internet
Author: User

Click here to transfer HDU 5391
Alas, I thought that with 7 is basically a prime number, so always take 1007 to calculate, the result .... Alas, a bitter tear ah, forget, do not say, on the matter:

Problem Descriptiontina Town isA friendly place. People there care AboutEach of the other. Tina has a ball called Zball. Zball isMagic. It grows largerevery  Day. On the  First  Day,itbecomes111  Time  asLarge as  itsOriginal size. On the Second  Day,itwould become222  Times  asLarge as  theSize on  the  First  Day. On theN-th Day,itwould become NNN Times  asLarge as  theSize on  the(n1)-th Day. Tina want toKnow itsSize on  the(n1)-th DayModulo n.inputthe FirstLine ofInputcontainsAnintegerTTT, representing the  Number  ofCases. The following TTT lines, each linecontainsAnintegerNNN, according to  theDescription. T≤ the,2≤n≤109T \leq {Ten}^{5},2\leq N \leq {Ten}^{9} t≤Ten?5??,2≤n≤Ten?9?? Outputfor each test case, output anintegerRepresenting theAnswer. Sample Input23TenSample Output20

The main idea: is to calculate (n-1)!%n,
Problem-solving ideas: Alas, that is, when the prime number, take n-1, is the time of composite is 0, except 4, when the n==4 of the time to take 2;

Note 1007 is not a prime number

#include <iostream>#include <cstdio>#include <cstring>using namespace STD;typedef Long LongLL;Const intMAXN =1e5;BOOLDATA[MAXN]; LL fac[10000];intCNT =0;voidIsPrime () {memset(Data,1,sizeof(data)); for(LL i=2; i<maxn; i++) {if(Data[i]) {fac[cnt++]=i; for(LL j=i*i; j<maxn; j+=i) data[j] =0; }    }}intMain () {intT,m;//cnt = 0;IsPrime ();scanf("%d", &t); while(t--) {scanf("%d", &m);if(M = =4)cout<<2<<endl;Else{intFlag =0; for(intI=0; i<cnt; i++) {//cout<<fac[i]<< "";                if(Fac[i]*fac[i] > m) Break;if(m%fac[i]==0) {flag=1;//cout<<flag<<endl;                     Break; }            }if(Flag = =1)puts("0");Else                printf("%d\n", M-1); }    }return 0;}

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

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.