HDU 5391-zball in Tina town (number theory)

Source: Internet
Author: User

Title Address: HDU 5391
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 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.
Idea: The problem is to ask N (n?1)! N If n is composite, the answer is obviously 0. If n is a prime number, then the answer is n-1 by Wilson's theorem. Pay attention to the case of n=4, the output is 2.

#include <stdio.h>#include <math.h>#include <string.h>#include <stdlib.h>#include <iostream>#include <sstream>#include <algorithm>#include <set>#include <queue>#include <stack>#include <map>#pragma COMMENT (linker, "/stack:102400000,102400000")using namespace STD;typedef__int64 LL;Const intinf=0x3f3f3f3f;Const DoublePi=ACOs(-1.0);Const Doubleesp=1e-7;intMain () {intT,n,i;scanf("%d", &t); while(t--) {scanf("%d", &n);if(n==4) {puts("2");Continue; }intflag=0;intm=sqrt(n1); for(i=2; i<=m; i++)if(n%i==0) {flag=1; Break; }if(!flag)printf("%d\n", N-1);Else            printf("0\n"); }return 0;}

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

HDU 5391-zball in Tina town (number theory)

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.