hdu5391 Zball in Tina Town(威尔逊定理)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud
Zball in Tina Town
Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 219 Accepted Submission(s): 144
Tina has a ball called zball. Zball is magic. It grows larger every day. On the first day, it becomes 1 time as large as its original size. On the second day,it will become 2 times as large as the size on the first day. On the n-th day,it will become n times as large as the size on the (n-1)-th day. Tina want to know its size on the (n-1)-th day modulo n.
The following T lines, each line contains an integer n, according to the description.
T≤105,2≤n≤109
题意:要求(n-1)! mod n
根据威尔逊定理,n为素数的时候(n-1)! mod n = -1 = n - 1,这是个充要条件
在n不是素数的时候,可以发现,只有4不为0,其余的时候都为0
/**
* code generated by JHelper
* More info: https://github.com/AlexeyDmitriev/JHelper
* @author xyiyy @https://github.com/xyiyy
*/ #include <iostream>
#include <fstream> //#####################
//Author:fraud
//Blog: http://www.cnblogs.com/fraud/
//#####################
//#pragma comment(linker, "/STACK:102400000,102400000")
#include <iostream>
#include <sstream>
#include <ios>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <vector>
#include <string>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <cctype> using namespace std; //
// Created by xyiyy on 2015/8/7.
// #ifndef ICPC_SCANNER_HPP
#define ICPC_SCANNER_HPP #endif //ICPC_SCANNER_HPP class hdu5391 {
public:
void solve(std::istream &in, std::ostream &out) {
int t;
in >> t;
while (t--) {
int n;
in >> n;
if (check(n))out << n - << endl;
else if (n == )out << << endl;
else out << << endl;
}
} bool check(int x) {
for (int i = ; i * i <= x; i++) {
if (x % i == ) {
return ;
}
}
return ;
}
}; int main() {
std::ios::sync_with_stdio(false);
std::cin.tie();
hdu5391 solver;
std::istream &in(std::cin);
std::ostream &out(std::cout);
solver.solve(in, out);
return ;
}
hdu5391 Zball in Tina Town(威尔逊定理)的更多相关文章
- hdu 5391 Zball in Tina Town 威尔逊定理 数学
Zball in Tina Town Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Oth ...
- HDU-5391 Zball in Tina Town
(n-1)!/n 就是如果n为素数,就等于n-1else为0. 求素数表: Zball in Tina Town Time Limit: 3000/1500 MS (Java/Others) Memo ...
- hdu5391 Zball in Tina Town
Problem Description Tina Town is a friendly place. People there care about each other. Tina has a ba ...
- HDU 5391 Zball in Tina Town【威尔逊定理】
<题目链接> Zball in Tina Town Problem Description Tina Town is a friendly place. People there care ...
- C#版 - HDUoj 5391 - Zball in Tina Town(素数) - 题解
版权声明: 本文为博主Bravo Yeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址 http://blog.csdn.net/lzuacm. HDUoj 5 ...
- 判素数+找规律 BestCoder Round #51 (div.2) 1001 Zball in Tina Town
题目传送门 /* 题意: 求(n-1)! mod n 数论:没啥意思,打个表能发现规律,但坑点是4时要特判! */ /***************************************** ...
- BC - Zball in Tina Town (质数 + 找规律)
Zball in Tina Town Accepts: 541 Submissions: 2463 Time Limit: 3000/1500 MS (Java/Others) Memory ...
- Zball in Tina Town
Zball in Tina Town Accepts: 356 Submissions: 2463 Time Limit: 3000/1500 MS (Java/Others) Memory ...
- 【HDU5391】Zball in Tina Town
[题目大意] 一个球初始体积为1,一天天变大,第一天变大1倍,第二天变大2倍,第n天变大n倍.问当第 n-1天的时候,体积变为多少.注意答案对n取模. [题解] 根据威尔逊定理:(n-1)! mod ...
随机推荐
- 线性表链式存储方式的C语言实现
/* 编译器:Dev-c++ 5.1.0 文件名:linkList3.cpp 代码版本号:1.0 时间:2015年9月24日11:34:16 */ #include <stdio.h> # ...
- AtomicInteger小小的理解
这里仅仅是验证多线程环境下,AtomicInteger的安全性. 通过源码不难发现两点: 1.value属性是volatile修饰 2.使用了unsafe的CAS操作 通过上述两点,实现非阻塞同步(乐 ...
- recovery编译汉化源码开源地址
本Recovery基于xiaolu开源的不完全汉化版源码,进行完全汉化,并合并Philz的最新源码. 汉化耗费我将近一整天的精力,纯手打,可能有遗漏或翻译不准的地方,请到微博反馈 本Rec完全开源,便 ...
- C# and android
http://www.cnblogs.com/GoodHelper/archive/2011/07/08/android_socket_chart.html http://blog.csdn.net/ ...
- JAVA中,数组的操作与排序
自己写了正向反向的冒泡排序,还用了静态和NEW方法实现. import java.util.Arrays; public class HelloJava { public static void ma ...
- Delphi从内存流中判断图片格式(好多相关文章)
废话不多说了,利用内存流来判断文件的格式,其实判断文件的前几个字节就可以简单的判断这个文件是什么类型的文件,例如jpg文件 是 FFD8 (从低位到高位就要反过来 D8FF 下面都是一样)BMP文件 ...
- RTSP,RTP,RTCP的区别
下面的文章讲解的都非常详细,可以参考OpenRTSP的源码学习.这个是live555库里面的工具Demo http://www.360doc.com/content/12/0516/23/782850 ...
- 神舟飞船上的计算机使用什么操作系统,为什么是自研发不是 Linux?
中国航天用的SpaceOS主要内容是仿造美国风河系统公司的VxWorks653(653是产品名,并非版本号). 先解释为什么用这个系统不用Linux: 航天器的内存和CPU都非常弱,弱到什么程度呢:天 ...
- rsyslog 读取单个文件测试
rsyslog 测试(rsyslog 必须yum 安装uat-web02:/root# rpm -qa | grep rsyslog rsyslog-8.21.0-1.el6.x86_64) //读取 ...
- BZOJ3392: [Usaco2005 Feb]Part Acquisition 交易
3392: [Usaco2005 Feb]Part Acquisition 交易 Time Limit: 5 Sec Memory Limit: 128 MBSubmit: 26 Solved: ...