HDU 5391 Zball in Tina Town (table, water)

Source: Internet
Author: User

Test instructions

Tina has a ball whose name is Zball. Zball is amazing, it gets bigger every day. On the first day, it will be 1 time times bigger. On the second day, it will be twice times bigger. In the nth day, it will become large n times.
The original volume of Zball is 1. Tina would like to know how big the volume of the Zball in the first n−1 is to n modulus?

Idea: If n is a composite, then it must be a factor, that is, there are two smaller numbers a and B, making a*b=n, then the answer must be 0. If it is a prime number, it is n-1 to hit the table. Small number of direct calculation, to prevent accidents. Numbers do not exceed int.

#include <cstdio>#include<iostream>#include<cstring>#include<cmath>#include<vector>#include<algorithm>#defineLL Long Long#defineINF 0x7f7f7f7fusing namespacestd;intans[10000];BOOLIsprimenumber (intN) {if(n==2)return true; if(n==1|| n&1==0)return false; intTMP =sqrt (N);  for(intj =2; J <= tmp; J + +)        if(N% J = =0)            return false; return true;}intMain () {//freopen ("Input.txt", "R", stdin);    intT, N; LL sum=0;  for(intI=2; i<= +; i++) {sum=1;  for(intj=1; j<i; J + +) {sum=sum*j%i; } Ans[i]=sum; } CIN>>T;  while(t--) {scanf ("%d",&N); if(n< +) {printf ("%d\n", Ans[n]); Continue; }        if(Isprimenumber (n)) printf ("%d\n", N-1); Elseprintf"0\n"); }    return 0;}
AC Code

HDU 5391 Zball in Tina Town (table, water)

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.