----------- 10^18

#include <bits/stdc++.h>
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
using namespace std;
typedef long long ll;
inline int read() {
int f=1,sum=0;
char x=getchar();
for(;(x<'0'||x>'9');x=getchar()) if(x=='-') f=-1;
for(;x>='0'&&x<='9';x=getchar()) sum=sum*10+x-'0';
return f*sum;
} int x_[10]={3,5,7,11,13,17,19,23}; inline ll mul(ll x,ll y,ll mod) {
ll tmp=x*y-((ll)((long double)x/mod*y+0.5))*mod;
return tmp<0?tmp+mod:tmp;
} inline ll qmul(ll x,ll ci,ll mod) {
ll sum=1;
for(;ci;ci>>=1,x=mul(x,x,mod))
if(ci&1) sum=mul(sum,x,mod);
return sum;
} inline bool Miller_Rabin(ll n) {
if(n==1) return 0;
if(n==2) return 1;
if(!(n&1)) return 0;
ll t=n-1;
int now=0;
while (!(t&1)) t>>=1,++now; for(int i = 0; i <= 7; i++){
if(x_[i]==n) return 1;
ll x=qmul(x_[i],t,n),y=x;
for(int j = 1; j <= now; j++) {
x=mul(x,x,n);
if(x==1&&!(y==1||y==n-1)) return 0;
y=x;
}
if(x!=1) return 0;
}
return 1;
} int main () {
//freopen("a.in","r",stdin);
ll x;
while (scanf("%lld",&x)==1) {
if(Miller_Rabin(x)) puts("Y");
else puts("N");
}
}

最新文章

  1. 错误&quot;ORA-04091: table is mutating, trigger/function may not see it&quot;的原因以及解决办法
  2. Android_SQLite版本升级,降级 管理
  3. atoi()函数
  4. jquery查找父元素、子元素(个人经验总结)
  5. DisableExplicitGC和Direct ByteBuffer
  6. css:中文词不断开,整体换行
  7. linux的学习系列 4---文件权限和访问模式
  8. MUI开发记录——我的考勤
  9. Java SE 8 流库(二)
  10. 2.python中self详解(程序适用于python3版本)
  11. NOIP 2018 大翻车记
  12. 【NLP】Conditional Language Models
  13. Python中的Numpy入门教程
  14. lightswitch binding custom control
  15. individual reading task ---12061183 叶露婷
  16. array_multisort
  17. adb常用命令及详解
  18. AngularJs 1.x和AngularJs2的区别
  19. Python: 字典列表: 通过某个字段将记录分组
  20. 求Read Depth

热门文章

  1. H5 存储数据sessionStorage
  2. 2018-2-13-WPF-拖动时出现-Invalid-FORMATETC-structure
  3. UVa 10603 Fill [暴力枚举、路径搜索]
  4. P1066 汪老师玩卡片
  5. H3C根桥的选举
  6. AutoHotKey 用打码的快捷键
  7. Linux 内核kobject 层次, kset, 和子系统
  8. es6笔记 day4---模块化
  9. LightOJ - 1265 Island of Survival (概率dp)
  10. How to fix nuget Unrecognized license type MIT when pack