BZOJ3884: The correct use of God and set

Source: Internet
Author: User

Description according to some books, God's one failure of the creation experience is this: the first day,God created the basic elements of a world, called "Yuan". The next day,God created a new element, called "alpha". "Alpha" is defined as a set of "meta" components. It is easy to see that there are two different "alpha" types. On the third day,God has created a new element called "beta". "Beta" is defined as a set of "alpha" components. It is easy to find a total of four different "beta". Day Fourth,God created the new element "gamma", "gamma" is defined as the set of "beta". Obviously, there will be 16 different "gamma" altogether. If this goes on, the fourth element God created will be 65536, and the fifth element will have 2^65536. This is going to be an astronomical one. However, God did not expect the growth of the number of elements to be so rapid. He wants to enrich the elements of the world, so, day after day, year after year, he repeats the creation of new elements ... But soon, when God created the last element, "Theta," he found that there were so many elements in the world that the world's capacity was inadequate and unbearable. So on this day, God destroys the world. So far, God remembers the failure of the creation experience, and now he wants to ask you how many of the elements he created last time, "Theta"? God thinks the number may be too large to be expressed, so you just need to answer the value of this number to P modulo. You can think of God from "alpha" to "theta" altogether creating 10^9 elements, or 10^18 times, or simply ∞ times. Sentence Test instructions:

Input Next T line, a positive integer p per line, represents the value you need to modulo

Outputt line, one positive integer per line, for the value after the answer p is modulo

Sample Input3
2
3
6Sample Output0
1
4HINT

For 100% of the data, T<=1000,p<=10^7 expands Euler's theorem: for any natural number a,n,p is established. Set Ans=f[p], because for any [1,10^7] integer, it can be up to a LOGN operation will become 1, so the violent demand for a single O (sqrt (n) logn).
#include <cstdio>#include<cctype>#include<queue>#include<cmath>#include<cstring>#include<algorithm>#defineRep (i,s,t) for (int i=s;i<=t;i++)#defineDwn (i,s,t) for (int i=s;i>=t;i--)#defineren for (int i=first[x];i;i=next[i])using namespaceStd;inlineintRead () {intx=0, f=1;CharC=GetChar ();  for(;! IsDigit (c); C=getchar ())if(c=='-') f=-1;  for(; IsDigit (c); C=getchar ()) x=x*Ten+c-'0'; returnx*F;} typedefLong Longll;intPow (ll N,intMintp) {ll ans=1;  while(m) m&1? (ans*=n)%=p:1, (n*=n)%=p,m>>=1; return(int) ans;intPhiintN) {intans=N;  for(intI=2; i*i<=n;i++)if(n%i==0) {         while(n%i==0) n/=i; Ans=ans/i* (I-1); }    if(n>1) ans=ans/n* (n1); returnans;}intFintN) {if(n==1)return 0; intC=Phi (n); returnPow2, c+f (c), n);}intMain () {Dwn (T,read (),1) printf ("%d\n", F (read ())); return 0;}
View Code

BZOJ3884: The correct use of God and set

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.