BestCoder Round #51 (div.2)
明显是无良心的数学round= =
1000 Zball in Tina Town
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<cstring>
#define PAU putchar(' ')
#define ENT putchar('\n')
#define Safe 6
using namespace std;
typedef long long LL;
const int maxn=+;
LL gcd(LL a, LL b){
return b == ? a : gcd(b, a % b);
}
LL n, x, mx;
LL mul(LL a, LL b, LL p){
LL tmp = (a * b - (LL)((long double)a / p * b + 1e-) * p);
return tmp < ? tmp + p : tmp;
}
LL pow(LL a, LL b, LL p){
LL ans = ; a %= p;
for(LL i = b; i; i >>= , a = mul(a, a, p))
if(i & ) ans = mul(ans, a, p);
return ans;
}
bool check(LL a, LL n, LL r, LL s){
LL ans = pow(a, r, n), p = ans;
for(int i = ; i <= s; i ++){
ans = mul(ans, ans, n);
if(ans == && p != && p != n - ) return true;
p = ans;
}
if(ans != )return true;
return false;
}
bool MR(LL n){
if(n <= ) return false;
if(n == ) return true;
if(n % == ) return false;
LL r = n - , s = ;
while(r % == ) r /= , s ++;
for(int i = ; i < Safe; i ++)
if(check(rand() % (n - ) + , n, r, s)) return false;
return true;
}
inline LL read(){
LL x=;bool sig=;char ch=getchar();
for(;!isdigit(ch);ch=getchar())if(ch=='-')sig=;
for(;isdigit(ch);ch=getchar())x=*x+ch-'';
return sig?x:-x;
}
inline void write(LL x){
if(x==){putchar('');return;}if(x<)putchar('-'),x=-x;
int len=;static LL buf[];while(x)buf[len++]=x%,x/=;
for(int i=len-;i>=;i--)putchar(buf[i]+'');return;
}
int T;
int main(){
T=read();LL x;
while(T--){
x=read();
if(x==){write();ENT;continue;}
if(x==){write();ENT;continue;}
if(MR(x))write(x-),ENT;
else write(),ENT;
}
// for(LL x=1;x<=100;x++){
// LL fac=1;
// for(int i=2;i<x;i++)fac=fac*i%x;write(x);PAU;write(fac);ENT;
// }
return ;
}
然后这道题全场都被至少扣了一分,不明觉厉= =
1001 Infoplane in Tina Town
显然不可写= =div1都没有人过= =
BestCoder Round #51 (div.2)的更多相关文章
- 判素数+找规律 BestCoder Round #51 (div.2) 1001 Zball in Tina Town
题目传送门 /* 题意: 求(n-1)! mod n 数论:没啥意思,打个表能发现规律,但坑点是4时要特判! */ /***************************************** ...
- hdu 5636 搜索 BestCoder Round #74 (div.2)
Shortest Path Accepts: 40 Submissions: 610 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: ...
- BestCoder Round #69 (div.2) Baby Ming and Weight lifting(hdu 5610)
Baby Ming and Weight lifting Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K ( ...
- BestCoder Round #68 (div.2) tree(hdu 5606)
tree Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submis ...
- BestCoder Round #11 (Div. 2) 题解
HDOJ5054 Alice and Bob Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/O ...
- hdu5635 BestCoder Round #74 (div.2)
LCP Array Accepts: 131 Submissions: 1352 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 13 ...
- hdu5634 BestCoder Round #73 (div.1)
Rikka with Phi Accepts: 5 Submissions: 66 Time Limit: 16000/8000 MS (Java/Others) Memory Limit: ...
- hdu5631 BestCoder Round #73 (div.2)
Rikka with Graph Accepts: 123 Submissions: 525 Time Limit: 2000/1000 MS (Java/Others) Memory Lim ...
- hdu5630 BestCoder Round #73 (div.2)
Rikka with Chess Accepts: 393 Submissions: 548 Time Limit: 2000/1000 MS (Java/Others) Memory Lim ...
随机推荐
- express不是内部命令解决办法
安装nodejs后,安装express,cmd下命令:npm install express -g;之后敲入express -V会提示不是内部命令,是因为, 4.0版本中将命令工具分家出来了,所以我们 ...
- Deep Learning学习随记(二)Vectorized、PCA和Whitening
接着上次的记,前面看了稀疏自编码.按照讲义,接下来是Vectorized, 翻译成向量化?暂且这么认为吧. Vectorized: 这节是老师教我们编程技巧了,这个向量化的意思说白了就是利用已经被优化 ...
- ios8及以前的特性
目前最新系统为ios8.以下为历代系统的回顾: iOS 1 关键词:iPhone的诞生 也许放在现在来看,当时的情景很难想象.当第一代iPhone正式发布时,在某些功能和方面其实是要远远落后于当时的竞 ...
- delegate-使用笔记
public class testclass { public class ProductImages : Page { protected Repeater rptSmallUrls; protec ...
- SGU 135.Drawing Lines
水题,不说了. #include <iostream> using namespace std; int f[70000]={1}; int n; int main(){ cin>& ...
- 在CentOS 6.3中安装与配置JDK-7
在CentOS 6.3中安装与配置JDK-7 来源:互联网 作者:佚名 时间:02-07 16:28:33 [大 中 小] 在CentOS-6.3中安装与配置JDK-7,有需要的朋友可以参考下 安装说 ...
- CSAPP LAB: Buffer Overflow
这是CSAPP官网上的著名实验,通过注入汇编代码实现堆栈溢出攻击.实验材料可到我的github仓库 https://github.com/Cheukyin/CSAPP-LAB/ 选择buffer-ov ...
- WebDriverWait自定义等待事件
1. webDriverWait自定义WebElement类事件 public WebElement waitForElementVisible(WebDriver driver,final By l ...
- wdcp-apache开启KeepAlive提高响应速度
因为我们的网站,媒体文件,js文件,css文件等都在同一个服务器上,并且,我们网站有非常多的图片,所以当建立好tcp链接之后,不应该马上关闭连接,因为每建立一次连接还要进行dns解析,以及启动一个ht ...
- [ZHUAN]Flask学习记录之Flask-SQLAlchemy
From: http://www.cnblogs.com/agmcs/p/4445583.html 各种查询方式:http://www.360doc.com/content/12/0608/11/93 ...