zoukankan      html  css  js  c++  java
  • 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
    ");
            exit(0);
        }
        cin >> x;
        if(n == 12) {
            printf("%012I64d
    ", 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
    ", i);
                break;
            }
        }
        return 0;
    }
     
  • 相关阅读:
    如何分析matlab程序的主要效率问题
    matlab的二维卷积操作
    移动,联通,电信手机都属于什么频段?
    开始学习Python
    利用R进行多元线性回归分析
    PANGU---Planet and Asteroid Natural scene Generation Utility
    中兴N909手机关闭照相机声音
    0709 C语言常见误区----------函数指针问题
    0709 C语言常见误区----------二维数组做参数
    0707 父子进程之间传递文件描述符
  • 原文地址:https://www.cnblogs.com/cshg/p/5894704.html
Copyright © 2011-2022 走看看