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 ...
随机推荐
- Varnish的VCL
Varnish的子进程 VCL Varnish配置语言VCL是一种"域"专有类型的配置语言,用于描述Varnish Cache的请求处理和文档高速缓存策略. 当加载新配置时,Man ...
- 基于Linux系统的Shell编程-基础篇
1. Shell基础介绍 1.1 Shell编程的意义 为什么使用shell编程 节约时间 1.2 显示脚本执行过程 前面有+表示执行过的命令的 前面没有东西,表示输出到屏幕上的内容. [root@C ...
- php编译安装参数详解
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/loc ...
- ngCordova插件说明
转载自 http://my.oschina.net/u/1416844/blog/495026 参 考http://blog.csdn.net/superjunjin/article/details/ ...
- 【工具】---- json-server基本使用
一.概念 在开发过程中,前端通常需要等待后端开发完接口后,再调用接口渲染相应的数据,这会影响开发效率.而json-server的作用就是为了解决前后端并行开发的痛点,在本地模拟后端接口用来测试前端效果 ...
- xshell、xftp最新版下载方法
https://www.netsarang.com/download/main.html 登录邮箱打开第一个下载地址进行下载
- Java多线程(十)线程间通信 join
若果主线程想等待子线程执行完成之后再结束,可以用join方法 join 和sleep区别 join内部有wait实现,所以当执行join方法后,当前线程的锁被释放,那么其他线程就可以调用此线程的同步方 ...
- Spring加载applicationContext.xml实现spring容器管理的几种方式
package com.etc.test; import org.junit.Test; import org.springframework.beans.factory.BeanFactory; i ...
- 块级标签与预格式化文本标签----------大多数XHTML可以表示为两种类型的标签:块标签(block tag)和内联标签(inline tag)
<html> <head> <meta charset="utf-8"> <title>块级标签</title> < ...
- JAVAEE 是什么,如何获取各种规范jar包及各种规范的jar包源码
1.什么是JAVA EE JAVA EE是由一系列规范组成的,规范是由JCP制定的,并且提供了参考实现.规范(Specification)是一系列接口,不包含具体实现 有以下常见的JAVA EE实现, ...