CodeForcesGym 100753K Upside down primes
Upside down primes
This problem will be judged on CodeForcesGym. Original ID: 100753K
64-bit integer IO format: %I64d Java class name: (Any)

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL mul(LL a,LL b,LL mod) {
if(!a) return ;
return ((a&)*b%mod + (mul(a>>,b,mod)<<)%mod)%mod;
}
LL quickPow(LL a,LL d,LL n){
LL ret = ;
while(d){
if(d&) ret = mul(ret,a,n);
d >>= ;
a = mul(a,a,n);
}
return ret;
}
bool check(LL a,LL d,LL n){
if(n == a) return true;
while(~d&) d >>= ;
LL t = quickPow(a,d,n);
while(d < n- && t != && t != n-){
t = mul(t,t,n);
d <<= ;
}
return (d&)||t == n-;
}
bool isP(LL n){
if(n == ) return true;
if(n < || == (n&)) return false;
static int p[] = {,,,,,,};
for(int i = ; i < ; ++i)
if(!check(p[i],n-,n)) return false;
return true;
} bool trans(LL x){
char str[];
sprintf(str,"%I64d",x);
for(int i = ; str[i]; ++i)
if(str[i] == '' || str[i] == '' || str[i] == '') return false;
reverse(str,str + strlen(str));
for(int i = ; str[i]; ++i)
if(str[i] == '') str[i] = '';
else if(str[i] == '') str[i] = '';
sscanf(str,"%I64d",&x);
return isP(x);
}
int main(){
LL x;
while(~scanf("%I64d",&x)){
if(isP(x) && trans(x)) puts("yes");
else puts("no");
}
return ;
}
CodeForcesGym 100753K Upside down primes的更多相关文章
- 计蒜客 18492.Upside down primes-米勒拉宾判大素数 (German Collegiate Programming Contest 2015 ACM-ICPC Asia Training League 暑假第一阶段第三场 K)
K. Upside down primes 传送门 这个题就是把大数按字符串输进去,判断一下是不是素数,然后反转180度,先判断反转之后的东西是不是一个数,如果是的话,再把这个数判一下是不是素数,如果 ...
- 2015 German Collegiate Programming Contest (GCPC 15) + POI 10-T3(12/13)
$$2015\ German\ Collegiate\ Programming\ Contest\ (GCPC 15) + POI 10-T3$$ \(A.\ Journey\ to\ Greece\ ...
- [LeetCode] Count Primes 质数的个数
Description: Count the number of prime numbers less than a non-negative number, n click to show more ...
- [LeetCode] Binary Tree Upside Down 二叉树的上下颠倒
Given a binary tree where all the right nodes are either leaf nodes with a sibling (a left node that ...
- projecteuler Summation of primes
The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. Find the sum of all the primes below two milli ...
- leetcode-Count Primes 以及python的小特性
题目大家都非常熟悉,求小于n的所有素数的个数. 自己写的python 代码老是通不过时间门槛,无奈去看了看大家写的code.下面是我看到的投票最高的code: class Solution: # @p ...
- Binary Tree Upside Down
Given a binary tree where all the right nodes are either leaf nodes with a sibling (a left node that ...
- Count Primes - LeetCode
examination questions Description: Count the number of prime numbers less than a non-negative number ...
- [leetcode] Count Primes
Count Primes Description: Count the number of prime numbers less than a non-negative number, n click ...
随机推荐
- datatable-bootstrap 基本配置
function doSearch() { if(dtable!=null){ dtable.fnClearTable(0); dtable.fnDraw(); // 重新加载数据 }else{ dt ...
- ElementaryOS 0.4快速配置工具
使用方法: 终端执行 wget http://linux-1251056822.costj.myqcloud.com/elementary_config && bash element ...
- 洛谷 P3437 [POI2006]TET-Tetris 3D
二维线段树区间更新啊 树套树的外层树,如果是线段树的话一般似乎不能打标记?(毕竟标记不好下传) 然而起码对于这题是可以的...对于外层线段树,每个节点放两个内层线段树dat和setv,分别是得到的值和 ...
- 383 Ransom Note 赎金信
给定一个赎金信 (ransom) 字符串和一个杂志(magazine)字符串,判断第一个字符串ransom能不能由第二个字符串magazines里面的字符构成.如果可以构成,返回 true :否则返回 ...
- 浅谈.net remoting 与 webservice
1. .NET Remoting .NET Remoting是微软随.NET推出的一种分布式应用解决方案,被誉为管理应用程序域之间的 RPC 的首选技,它允许不同应用程序域之间进行通信(这里的通信可以 ...
- MVC之参数验证(二)
MVC内部针对这此验证是如何实现的咧???现在我们就来分析一下这此验证的背后故事.... 1.ModelValidator与ModelValidatorProvider 虽然Model绑定方式的因绑定 ...
- 重新学习Java——Java基本的程序设计结构(一)
最近在实验室看到各位学长忙于找工作的面试与笔试,深感自己的不足,决定重新好好学习一下<Java核心技术>这本书,曾经靠这本书走入Java的世界,但是也有很多的地方被我疏漏过去了,因此也是作 ...
- taskctl命令行类(sh、exe、python新增scp)插件升级扩展
转载自: http://www.taskctl.com/forum/detail_129.html 上次写了一个帖子 TASKCTL中不使用代理,通过ssh免密连接执行远程脚本配置(SSH插件扩展)h ...
- Java 基础入门随笔(3) JavaSE版——逻辑运算符、位运算符
上一节写了一些运算符的注意事项,这节开头依然是对运算符的一些注意点的阐述! 比较运算符除了>.>=.<.<=.==.!=之外需要注意instanceof:检查是否是类的对象,例 ...
- spring思想分析
摘要: EveryBody in the world should learn how to program a computer...because it teaches you how to th ...