1343. Fairy Tale

Time limit: 1.0 second
Memory limit: 64 MB
12 months to sing and dance in a ring their celestial dance. One after another they hold a throne. The first is young and fierce January and the last is elderly and wise December. Leaving the throne, every month cry out a digit. During a year a 12-digit number is formed. The Old Year uses this number as a shield on his way to the Abyss of Time. He defend himself with this shield from the dreadful creatures of Eternity. Because of hard blows the shield breaks to pieces corresponding to the divisors of the number.
Your task is to help the months to forge the shield for the Old Year such that it couldn’t be broken to pieces.

Input

The first line contains a number of months that already left the throne. The second line contains the digits already cried out.

Output

Output an arbitrary 12-digits integer that starts with the given digits and that has no nontrivial divisors. It’s guaranteed that the solution exists.

Sample

input output
5
64631
646310554187
Problem Author: Pavel Atnashev
Problem Source: USU Championship 2004
Difficulty: 411  
 
题意:给定一个数,求一个这个数开头的12位素数
分析:既然时限这么宽,就随机好了
事实上枚举通过了这题。。。
 /**
Create By yzx - stupidboy
*/
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <ctime>
#include <iomanip>
using namespace std;
typedef long long LL;
typedef double DB;
#define For(i, s, t) for(int i = (s); i <= (t); i++)
#define Ford(i, s, t) for(int i = (s); i >= (t); i--)
#define Rep(i, t) for(int i = (0); i < (t); i++)
#define Repn(i, t) for(int i = ((t)-1); i >= (0); i--)
#define rep(i, x, t) for(int i = (x); i < (t); i++)
#define MIT (2147483647)
#define INF (1000000001)
#define MLL (1000000000000000001LL)
#define sz(x) ((int) (x).size())
#define clr(x, y) memset(x, y, sizeof(x))
#define puf push_front
#define pub push_back
#define pof pop_front
#define pob pop_back
#define ft first
#define sd second
#define mk make_pair
inline void SetIO(string Name)
{
string Input = Name+".in",
Output = Name+".out";
freopen(Input.c_str(), "r", stdin),
freopen(Output.c_str(), "w", stdout);
} inline int Getint()
{
int Ret = ;
char Ch = ' ';
bool Flag = ;
while(!(Ch >= '' && Ch <= ''))
{
if(Ch == '-') Flag ^= ;
Ch = getchar();
}
while(Ch >= '' && Ch <= '')
{
Ret = Ret * + Ch - '';
Ch = getchar();
}
return Flag ? -Ret : Ret;
} const int N = ;
int Prime[N], Tot;
bool Visit[N];
int m;
LL n, Fact[]; inline void getPrime()
{
For(i, , N - )
{
if(!Visit[i]) Prime[++Tot] = i;
For(j, , Tot)
{
if(i * Prime[j] >= N) break;
Visit[i * Prime[j]] = ;
if(i % Prime[j] == ) break;
}
}
} inline void Input()
{
getPrime();
scanf("%d", &m);
if(m) cin >> n;
} inline bool isPrime(LL x)
{
if(x <= ) return ;
For(i, , Tot)
{
if(x <= Prime[i]) break;
if(x % Prime[i] == ) return ;
}
return ;
} inline void Solve()
{
srand(time());
Fact[] = ;
For(i, , ) Fact[i] = Fact[i - ] * 10LL; LL Tmp = n * Fact[ - m];
//isPrime(277717333835LL);
while(!isPrime(Tmp))
{
Tmp = n * Fact[ - m];
For(i, m + , )
Tmp += (rand() % ) * Fact[ - i];
} printf("%012I64d\n", Tmp);
} int main()
{
#ifndef ONLINE_JUDGE
SetIO("F");
#endif
Input();
Solve();
return ;
}

ural 1343. Fairy Tale的更多相关文章

  1. 1343. Fairy Tale

    1343 想了好一会 以为会有什么定理呢 没想到 就试着搜了 看来素数还是很多的 跑的飞快 注意会有前导0的情况 还有0,1不是素数... #include <iostream> #inc ...

  2. Codeforces Round #404 (Div. 2) C. Anton and Fairy Tale 二分

    C. Anton and Fairy Tale 题目连接: http://codeforces.com/contest/785/problem/C Description Anton likes to ...

  3. URAL 1513 Lemon Tale

    URAL 1513 思路: dp+高精度 状态:dp[i][j]表示长度为i末尾连续j个L的方案数 初始状态:dp[0][0]=1 状态转移:dp[i][j]=dp[i-1][j-1](0<=j ...

  4. URAL 1513. Lemon Tale(简单的递推)

    写几组数据就会发现规律了啊. .但是我是竖着看的.. .还找了半天啊... 只是要用高精度来写,水题啊.就当熟悉一下java了啊. num[i] = 2*num[i-1]-num[i-2-k]. 15 ...

  5. NSOJ A fairy tale of the two(最小费用最大流、SPFA版本、ZKW版本)

    n,m<=20,给两个n×m布尔矩阵,每次操作可将第一个矩阵的2个相邻元素互换.输出最少操作次数使得两个矩阵完全一样. 比赛的时候想过按照二分图完美匹配的类似做法构图,不过想到边太多以及卡各种题 ...

  6. C. Anton and Fairy Tale

    链接 [https://codeforces.com/contest/785/problem/C] 题意 初始时有n,第1天先加m开始吃1,但总的不能超过n,第i天先加m开始吃i(如果不够或刚好就吃完 ...

  7. CodeForces 785C Anton and Fairy Tale

    二分. 如果$n≤m$,显然只能$n$天. 如果$n>m$,至少可以$m$天,剩余还可以支撑多少天,可以二分计算得到,也可以推公式.二分计算的话可能爆$long$ $long$,上了个$Java ...

  8. 【二分】Codeforces Round #404 (Div. 2) C. Anton and Fairy Tale

    当m>=n时,显然答案是n: 若m<n,在第m天之后,每天粮仓减少的量会形成等差数列,只需要二分到底在第几天,粮仓第一次下降到0即可. 若直接解不等式,可能会有误差,需要在答案旁边扫一下. ...

  9. CodeForces 785C Anton and Fairy Tale 二分

    题意: 有一个谷仓容量为\(n\),谷仓第一天是满的,然后每天都发生这两件事: 往谷仓中放\(m\)个谷子,多出来的忽略掉 第\(i\)天来\(i\)只麻雀,吃掉\(i\)个谷子 求多少天后谷仓会空 ...

随机推荐

  1. Lambda表达式与标准运算符查询

    class Program { static void Main(string[] args) { //Lambda表达式输出List集合每一项 List<string> list = n ...

  2. NYOJ题目813对决

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAssAAALRCAIAAAAiJ3lxAAAgAElEQVR4nO3dPW7jSgMu6LsJ516IYy

  3. inode

    硬盘的最小存储单位叫"扇区(sector)",每个扇区存储512字节(相当于0.5kb).系统读取硬盘时,只会读取多个sector即一个block.block 是文件存取的最小单位 ...

  4. OID View

    http://oid-info.com/get/1.3.6.1.2.1.17.1.4.1.2

  5. 【PHP构造方法和析构方法的使用】

    构造方法:__construct,析构方法:__destruct 代码示例: <?php class Person { public $name; public $age; public fun ...

  6. scala的tcp通信

    client: object ActorClient extends App { import actors.Actor, actors.remote.Node, actors.remote.Remo ...

  7. 手机web页面制作时的注意事项

    一.手机页面的标准头规范 字符编码使用utf-:指定页面手机内存缓存中的存储时间段 device-width:通知浏览器使用设备的宽度作为可视区的宽度 initial-scale - 初始的缩放比例 ...

  8. hdu 5033 单调栈 ****

    看出来是单调栈维护斜率,但是不会写,2333,原来是和询问放在一起的 #include <iostream> #include <cstdio> #include <cs ...

  9. em与rem

    em是相对于父元素的font-size,rem是相对于根元素的font-size. rem的补充: ① 对于不支持它的浏览器,应对方法也很简单,就是多写一个绝对单位的声明.这些浏览器会忽略用rem设定 ...

  10. LoadRunner检查点学习实例

    LoadRunner只会检测脚本中事务的执行状态,而实际的事务执行结果则需要通过检查点来完成. 例如一个登录事务,LR只关心事务本身的执行状态,也就是说哪怕实际操作密码错误产生登录失败的业务操作,其事 ...