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. Unity使用外部版本控制

    Using External Version Control Systems with Unity Unity offers an Asset Server add-on product for ea ...

  2. bzoj 1646: [Usaco2007 Open]Catch That Cow 抓住那只牛【bfs】

    满脑子dp简直魔性 模拟题意bfs转移即可 #include<iostream> #include<cstdio> #include<queue> using na ...

  3. echarts-gl 3D柱状图保存为图片,打印

    echarts-gl生成的立体柱状图生成图片是平面的,但是需求是3D图并且可以打印,我们的思路是先转成图片,然后再打印,代码如下: 生成3D图 <td>图表分析</td> &l ...

  4. jQuery——表单应用(4)

    HTML: <!--复选框应用--> <!DOCTYPE html> <html> <head> <meta charset="UTF- ...

  5. Java多线程(一) Thread和 Runnable

    http://www.cnblogs.com/lwbqqyumidi/p/3804883.html 1.继承Thread 2.实现Runnable接口 public class MyRunnable ...

  6. 数据传递-------@ResponseBody

    1.导入jar包 jack-core-asl-1.9.11.jar jack-mapper-asl-1.9.11.jar 2.配置springmvc-servlet.xml文件 <?xml ve ...

  7. EasyUI系列学习(十)-Tabs(选项卡)

    一.创建组件 <div class="easyui-tabs" style="width:500px;height:250px"> <div ...

  8. 一个JavaScript贷款计算器

    通过本案例,将会学到: . 如何在文档中查找元素 . 如何通过表单input元素来获取用户的输入数据 . 如何通过文档元素来设置HTML内容 . 如何将数据存储在浏览器中 . 如何使用脚本发起HTTP ...

  9. Java 创建Excel并逐行写入数据

    package com.xxx.common.excel; import java.io.File; import java.io.FileInputStream; import java.io.Fi ...

  10. leetcode126 Word Ladder II

    思路: 宽搜过程中分层记录路径,递归还原.实现: class Solution { public: void getPath(string now, string beginWord, string ...