Upside down primes

Time Limit: 2000ms
Memory Limit: 262144KB

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的更多相关文章

  1. 计蒜客 18492.Upside down primes-米勒拉宾判大素数 (German Collegiate Programming Contest 2015 ACM-ICPC Asia Training League 暑假第一阶段第三场 K)

    K. Upside down primes 传送门 这个题就是把大数按字符串输进去,判断一下是不是素数,然后反转180度,先判断反转之后的东西是不是一个数,如果是的话,再把这个数判一下是不是素数,如果 ...

  2. 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\ ...

  3. [LeetCode] Count Primes 质数的个数

    Description: Count the number of prime numbers less than a non-negative number, n click to show more ...

  4. [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 ...

  5. 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 ...

  6. leetcode-Count Primes 以及python的小特性

    题目大家都非常熟悉,求小于n的所有素数的个数. 自己写的python 代码老是通不过时间门槛,无奈去看了看大家写的code.下面是我看到的投票最高的code: class Solution: # @p ...

  7. Binary Tree Upside Down

    Given a binary tree where all the right nodes are either leaf nodes with a sibling (a left node that ...

  8. Count Primes - LeetCode

    examination questions Description: Count the number of prime numbers less than a non-negative number ...

  9. [leetcode] Count Primes

    Count Primes Description: Count the number of prime numbers less than a non-negative number, n click ...

随机推荐

  1. DNS中的AC、rndc、智能DNS解析和基础排错

    bind中的ACL和rndc DNS除了服务器外,还具有一些访问控制和视图功能. 访问控制是指仅对定义的网络进行解析,视图也就是智能解析. 1>访问控制是通过acl函数来实现的,acl把一个或多 ...

  2. sql2000数据库置疑造成的原因以及如何解决置疑

    造成数据库置疑一般有以下几点: 1)电脑非法关机或者意外停电: 2)磁盘有坏道或者损坏: 3)数据库感染病毒,日志文件损坏: 4)非正常情况下移动数据库文件 5)系统,硬盘,经常强制性关机(如断电)类 ...

  3. Python基础 — NumPy

    NumPy--简介  Numpy(Numerical Python的简称)是一个由多维数组对象和用于处理数组的例程集合组成的库.  Numpy内部解除了Python的PIL(全局解释器锁),运算效率极 ...

  4. bzoj 3390: [Usaco2004 Dec]Bad Cowtractors牛的报复【最大生成树】

    裸的最大生成树,注意判不连通情况 #include<iostream> #include<cstdio> #include<algorithm> using nam ...

  5. Android 性能优化(12)网络优化( 8)Monitoring the Battery Level and Charging State

    Monitoring the Battery Level and Charging State PreviousNext This lesson teaches you to Determine th ...

  6. Visual Studio 生成项目时脚本执行

    项目属性 - 生成事件 项目生成前:预先生成事件命令行: 项目生成后:后期生成事件命令行:例:copy $(ProjectDir)Reference\sms_cfg.ini $(TargetDir) ...

  7. 网站开发综合技术 一 JavaScript简介 二JavaScript语法

    第1部分 JavaScript简介 1.JavaScript它是个什么东西? 它是个脚本语言,需要有宿主文件,他的宿主文件是html文件. 2.它与Java有什么关系? 没有什么直接联系,java是S ...

  8. Spring-Aop的两种代理方式

    Spring-Aop两种代理方式: 1.JDK动态代理:用于目标类实现了接口: 2.Cglib动态代理:用于目标类没有实现接口: spring会依据目标类是否实现接口来选择使用哪种代理方式(目标类:相 ...

  9. maven build过程中遇到的问题以及解决方案

    (1)不支持泛型以及@Override 问题来源:使用了低版本的jdk,默认情况下maven使用的是jdk1.5的版本,而泛型和@Override是后期版本才有的,需要更改maven默认的jdk版本. ...

  10. WebApi实现IHttpControllerSelector问题

    一.让Web API路由配置也支持命名空间参数/// <summary>    /// controller     /// 选择器    /// </summary>    ...