zoukankan      html  css  js  c++  java
  • Codeforces Round #315 (Div. 2) C. Primes or Palindromes? 暴力

    C. Primes or Palindromes?
    time limit per test
    3 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Rikhail Mubinchik believes that the current definition of prime numbers is obsolete as they are too complex and unpredictable. A palindromic number is another matter. It is aesthetically pleasing, and it has a number of remarkable properties. Help Rikhail to convince the scientific community in this!

    Let us remind you that a number is called prime if it is integer larger than one, and is not divisible by any positive integer other than itself and one.

    Rikhail calls a number a palindromic if it is integer, positive, and its decimal representation without leading zeros is a palindrome, i.e. reads the same from left to right and right to left.

    One problem with prime numbers is that there are too many of them. Let's introduce the following notation: π(n) — the number of primes no larger than nrub(n) — the number of palindromic numbers no larger than n. Rikhail wants to prove that there are a lot more primes than palindromic ones.

    He asked you to solve the following problem: for a given value of the coefficient A find the maximum n, such that π(n) ≤ A·rub(n).

    Input

    The input consists of two positive integers pq, the numerator and denominator of the fraction that is the value of A ().

    Output

    If such maximum number exists, then print it. Otherwise, print "Palindromic tree is better than splay tree" (without the quotes).

    Examples
    input
    1 1
    output
    40
    input
    1 42
    output
    1
    input
    6 4
    output
    172
    题意:不大于n的素数的个数<=A*不大于n的回文数的个数;求最大的n
    思路:暴力;
    #include<bits/stdc++.h>
    using namespace std;
    int a[100];
    int check(int x)
    {
        int ji=0;
        while(x)
        {
            a[ji++]=x%10;
            x/=10;
        }
        for(int i=0;i<ji/2;i++)
        {
            if(a[i]!=a[ji-1-i])
            return 0;
        }
        return 1;
    }
    int prime(int n)
    {
        if(n<=1)
        return 0;
        if(n==2)
        return 1;
        if(n%2==0)
        return 0;
        int k, upperBound=n/2;
        for(k=3; k<=upperBound; k+=2)
        {
            upperBound=n/k;
            if(n%k==0)
                return 0;
        }
        return 1;
    }
    #define ll __int64
    const int N=2e6+10;
    ll p[N],h[N];
    int main()
    {
        for(ll i=1;i<=1200000;i++)
        {
            p[i]=p[i-1];
            h[i]=h[i-1];
            if(prime(i))
            p[i]++;
            if(check(i))
            h[i]++;
        }
        ll u,v;
        scanf("%I64d%I64d",&u,&v);
        for(int i=1200000;i>0;i--)
        if(v*p[i]<=u*h[i])
        {
            printf("%d
    ",i);
            return 0;
        }
        printf("Palindromic tree is better than splay tree
    ");
        return 0;
    }
  • 相关阅读:
    Shiro入门学习之shi.ini实现授权(三)
    Shiro入门学习之shi.ini实现认证及源码分析(二)
    猜字母游戏(Java)
    二维数组的语法
    鸡兔同笼问题(Java)
    成绩统计程序(Java)
    18位身份证验证(Java)加入身份证输入验证是否满足18位代码(修订稿)
    18位身份证验证(Java)
    键盘输入字符插入定义数组中并按顺序排列
    一个随机验证码且不重复的小程序以及求随机输入一组数组中的最大值(Java)
  • 原文地址:https://www.cnblogs.com/jhz033/p/5689618.html
Copyright © 2011-2022 走看看