ural 1343. Fairy Tale

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 ;
}
上一篇:C. Anton and Fairy Tale(数学推式子)


下一篇:1343. Fairy Tale