ural 1343. Fairy Tale打表

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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

inputoutput
5
64631
646310554187
Problem Author: Pavel Atnashev
Problem Source: USU Championship 2004
题目大意:给出前n位数, 然后补12-n位数,使得这个12位整数为素数
思路:打了一个1e7的素数表。。然而还要特别判断很多情况
也有大神随机。。。
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <cstring>
#define FOR(i, a, b)  for(int i = (a); i <= (b); i++)
#define RE(i, n) FOR(i, 1, n)
#define FORP(i, a, b) for(int i = (a); i >= (b); i--)
#define REP(i, n) for(int i = 0; i <(n); ++i)
#define SZ(x) ((int)(x).size )
#define ALL(x) (x).begin(), (x.end())
#define MSET(a, x) memset(a, x, sizeof(a))
using namespace std;


typedef long long int ll;
typedef pair<int, int> P;
int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<0||ch>9){if(ch==-)f=-1;ch=getchar();}
    while(ch>=0&&ch<=9){x=x*10+ch-0;ch=getchar();}
    return x*f;
}
const double pi=3.14159265358979323846264338327950288L;
const double eps=1e-6;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int MAXN = 1e7;
const int xi[] = {0, 0, 1, -1};
const int yi[] = {1, -1, 0, 0};

int N, T;
int prime[MAXN+10], cnt = 0;
int a[MAXN+10];

void init(){
    for(int i = 2; i <= MAXN; i++) a[i] = true;
    for(int i = 2; i <= MAXN; i++){
        if(a[i]){
            prime[++cnt] = i;
        }
        for(int j = 1; j <= cnt; j++){
            if(prime[j]*i > MAXN) break;
            a[prime[j]*i] = false;
            if(i%prime[j] == 0) break;
        }
    }
}

int main() {
    //freopen("in.txt", "r", stdin);
    int n;
    init();
    ll x, y = 1;
    cin >> n;
    if(n == 0){
        printf("000000000003\n");
        exit(0);
    }
    cin >> x;
    if(n == 12) {
        printf("%012I64d\n", x);
        exit(0);
    }
    for(int i = n; i < 12; i++) y *= 10;
    //cout << y << endl;
    //cout << y*x+1 <<" " <<y*(x+1) << endl;
    for(ll i = y*x+3; i < y*(x+1); i += 2){

        int flag = 1;
        for(int j = 1; j <= cnt  && prime[j] < i; j++){
            if(i%prime[j] == 0){
                flag = 0;
                break;
            }
        }
       // cout << i << endl;
        if(flag){
            printf("%012I64d\n", i);
            break;
        }
    }
    return 0;
}

 

 

以上是关于ural 1343. Fairy Tale打表的主要内容,如果未能解决你的问题,请参考以下文章

Anton and Fairy Tale

Anton and Fairy Tale (公式)

Anton and Fairy Tale (公式)

CodeForces 785C Anton and Fairy Tale

codeforces 785C Anton and Fairy Tale

URAL 1513 Lemon Tale