HDU 1431 思维 基础数论
找范围内回文素数,最大到1e8,我就是要枚举回文串,再判素数,然后因为这种弱智思路死磕了很久题目。
/** @Date : 2017-09-08 15:24:43
* @FileName: HDU 1431 思维 找回文素数.cpp
* @Platform: Windows
* @Author : Lweleth (SoungEarlf@gmail.com)
* @Link : https://github.com/
* @Version : $Id$
*/
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int ,int>
#define MP(x, y) make_pair((x),(y))
#define fi first
#define se second
#define PB(x) push_back((x))
#define MMG(x) memset((x), -1,sizeof(x))
#define MMF(x) memset((x),0,sizeof(x))
#define MMI(x) memset((x), INF, sizeof(x))
using namespace std; const int INF = 0x3f3f3f3f;
const int N = 1e5+20;
const double eps = 1e-8; LL pri[N];
bool vis[N];
int c = 0; void prime()
{
MMF(pri);
MMF(vis);
for(int i = 2; i < N; i++)
{
if(!vis[i])
pri[c++] = i;
for(int j = 0; j < c && i * pri[j] < N; j++)
{
vis[i * pri[j]] = 1;
if(i % pri[j] == 0) break;
}
}
} int isk[2010]; int main()
{
prime();
//freopen("x.txt","w", stdout);
LL a, b;
while(cin >> a >> b)
{
for(int i = 0; pri[i] < 10; i++)
if(pri[i] >= a && pri[i] <= b)
printf("%lld\n", pri[i]);
priority_queue<int, vector<int>, greater<int>>q;
for(int i = 1; i < 10000; i++)
{
int flag = log10(i);
for(int k = -1; k <= 9; k++)
{
int s = i * pow(10, flag + 1);
if(k > -1)
s = s * 10 + k * pow(10, flag + 1);
int t = i;
int cnt = flag;
//cout << s << "~";;
while(t)
{
s += (t % 10) * pow(10, cnt);
t /= 10;
cnt--;
}
if(s < a || s > b)
continue;
int flag = 0;
for(int j = 0; j < c && pri[j] * pri[j] <= s; j++)
if(s % pri[j] == 0)
{
flag = 1;
break;
}
if(!flag)
q.push(s)/*,cout << s << endl*/; }
}
while(!q.empty())
{
printf("%d\n", q.top());
q.pop();
}
printf("\n");
}
return 0;
}
HDU 1431 思维 基础数论的更多相关文章
- Gcd HDU - 6545 (基础数论)
wls 有一个整数 n,他想将 1 − n 这 n 个数字分成两组,每一组至少有一个数,并且使得两组数字的和的最大公约数最大,请输出最大的最大公约数. Input 输入一行一个整数 n. 2 ≤ n ...
- Least Common Multiple (HDU - 1019) 【简单数论】【LCM】【欧几里得辗转相除法】
Least Common Multiple (HDU - 1019) [简单数论][LCM][欧几里得辗转相除法] 标签: 入门讲座题解 数论 题目描述 The least common multip ...
- HDU 1005 Number Sequence(数论)
HDU 1005 Number Sequence(数论) Problem Description: A number sequence is defined as follows:f(1) = 1, ...
- HDU 2588 思维 容斥
求满足$1<=X<=N ,(X,N)>=M$的个数,其中$N, M (2<=N<=1000000000, 1<=M<=N)$. 首先,假定$(x, n)=m$ ...
- LightOJ1214 Large Division 基础数论+同余定理
Given two integers, a and b, you should check whether a is divisible by b or not. We know that an in ...
- HDU-1576 A/B 基础数论+解题报告
HDU-1576 A/B 基础数论+解题报告 题意 求(A/B)%9973,但由于A很大,我们只给出n(n=A%9973) (我们给定的A必能被B整除,且gcd(B,9973) = 1). 输入 数据 ...
- 七夕节 (HDU - 1215) 【简单数论】【找因数】
七夕节 (HDU - 1215) [简单数论][找因数] 标签: 入门讲座题解 数论 题目描述 七夕节那天,月老来到数字王国,他在城门上贴了一张告示,并且和数字王国的人们说:"你们想知道你们 ...
- HDU 1299 基础数论 分解
给一个数n问有多少种x,y的组合使$\frac{1}{x}+\frac{1}{y}=\frac{1}{n},x<=y$满足,设y = k + n,代入得到$x = \frac{n^2}{k} + ...
- HDU 1060 Leftmost Digit 基础数论
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1060 这道题运用的是数学方法. 假设S=n^n.两边同时取对数,得到lgS=nlgn.即有S=10 ...
随机推荐
- 【探路者】互评beta版本
成员博客 1蔺依铭:http://www.cnblogs.com/linym762/ 2张恩聚:http://www.cnblogs.com/zej87/ 3米赫:http://www.cnblogs ...
- static块的本质
在网上看到了下面的一段代码: public class Test { static { _i = 20; } public static int _i = 10; public static void ...
- 团队Alpha冲刺(六)
目录 组员情况 组员1(组长):胡绪佩 组员2:胡青元 组员3:庄卉 组员4:家灿 组员5:凯琳 组员6:翟丹丹 组员7:何家伟 组员8:政演 组员9:黄鸿杰 组员10:刘一好 组员11:何宇恒 展示 ...
- Java微笔记(5)
final关键字 super关键字
- Django之contenttypes的应用
Django contenttypes 应用 简介 contenttypes 是Django内置的一个应用,可以追踪项目中所有app和model的对应关系,并记录在ContentType表中. 每当我 ...
- 我的 MyBatis 实现的 Dao 层
学了 Mybatis 之后,发现用 Mybatis 写 Dao层实在是简便多了,主要是在表的映射这块简单了很多.下面是我实现的使用 Mybatis 实现的简单的操作用户表的 Dao 层. 使用 Myb ...
- Sass & Scss & CSS3
Sass & Scss & CSS3 Sass & Scss @mixin & @include & @import & variable https: ...
- SQL Inserted和deleted详解
create trigger updateDeleteTime on user for update as begin update user set UpdateTime=(getdate()) f ...
- MySQL 分组排序问题
SQL好久不写了,有些生疏了,一个分组排序问题想了快半天,整理下. 学生表 CREATE TABLE `t_student` ( `id` bigint(20) NOT NULL AUTO_INCRE ...
- 第180天:HTML5——本地存储
本地存储 客户端存储数据的方法 cookie 方法 localStorage方法 sessionStorage方法 一.localStorage 1.存储特点: localStorage方法存储的数据 ...