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 ...
随机推荐
- xml代码
修改和删除: <?php$doc=new DOMDocument();$doc->load("php.xml");$root=$doc->documentElem ...
- 用异提交时,后台通过校验规则文件,校验不通过时,跳转到INPUT视图时,前台显示错误信息的解决办法
1.第一种: 最近项目使用了struts2的校验(其实我觉得后台校验,特别是struts的校验,完全可以放在其他地方处理,比如交给js或者业务逻辑),而且系统刚好还使用了extjs,此时问题出现了:假 ...
- JS对undefined,null,NaN判断
1.判断undefined: <span style="font-size: small;">var tmp = undefined; if (typeof(tmp) ...
- 关于iOS上的对象映射公用方法-备
具体的使用方法,请见下面说明,或者见工程里的单元测试代码.或者,参考原始文档: https://github.com/mystcolor/JTObjectMapping 使用方法 ======== 绝 ...
- 摇滚吧HTML5!有声前端交互!(一)
生命的伊始,婴儿用明亮的哭声宣告一个新生命的诞生,睁开双眼之前,一双小耳朵已经开始聆听这个世界.在如今的用户体验领域,几乎所有公司都会有视觉设计师,却鲜有注重听觉交互的公司.随着各大厂商对HTML5支 ...
- Big Data Analytics for Security(Big Data Analytics for Security Intelligence)
http://www.infoq.com/articles/bigdata-analytics-for-security This article first appeared in the IEEE ...
- 温习PYTHON语法
看WEBPY的源码结构有点晕,原来很多语法结构都忘了,继承之些. 再看A BYTE OF PYTHON.慢慢补.. number = 23 guess = int(raw_input('Enter a ...
- LeetCode_Single Number II
Given an array of integers, every element appears three times except for one. Find that single one. ...
- Android TextView背景颜色与背景图片设置
Android TextView 背景颜色与背景图片设置,android textview 控件,android textview 背景, android textview 图片,android te ...
- delphi TCXTreelist 通过代码控制行的可编辑性
procedure TfrmSetOutPzTradeDeptPerson.grdTradeClientEditing(Sender: TObject; AColumn: TcxTreeListCo ...