codeforce 568A Primes or Palindromes?

本文提供了一道CodeForces竞赛题目568A的解题思路及代码实现。通过预处理素数和回文数,快速找到满足条件的最大整数。涉及素数筛法、回文数判断等算法。

【题目链接】http://codeforces.com/problemset/problem/568/A

【解题报告】
水题,看到时限在3s于是想到可以打一个千万级别的表(一不小心打到上亿的表跑了半天跑不出来TAT),先试着打了一个1e7的表,求出了1e7以内所有的pi[i]和rub[i]。然后题目是求出最大的满足pi[n]

#include<bits/stdc++.h>
using namespace std;

const int maxn=1e7+10;

int vis[maxn+10],pi[maxn+10],rub[maxn+10];

void getprime(  int n )
{
    memset(vis,0,sizeof(vis));
      vis[1]=1;
    for(int i=2;i<=n;i++)
        for(int j=2*i;j<=n;j+=i)if(!vis[j])
            vis[j]=1;

}

bool is_pld(int num)
{
    int len=0;
    int s[100];
    while(num)
    {
        s[++len]=num%10;
        num/=10;
    }
    for(int i=1;i<=len/2;i++)
        if( s[i]!=s[len-i+1] )return false;
    return true;

}

int main()
{
    getprime(maxn);
    pi[0]=0;
    for(int i=1;i<=maxn;i++)if(!vis[i])pi[i]=pi[i-1]+1;else pi[i]=pi[i-1];
    rub[0]=0;
    for(int i=1;i<=maxn;i++)
    {
        rub[i]=rub[i-1];
        if(is_pld(i))rub[i]++;
    }

    double p,q;
    cin>>p>>q;
    double A=p/q;
    for(int i=maxn;i>=1;i--)if(pi[i]<=A*rub[i])
    {
        cout<<i<<endl;
        return 0;
    }
    cout<<"Palindromic tree is better than splay tree\n";

    return 0;
}
### Codeforces Problem or Contest 998 Information For the specific details on Codeforces problem or contest numbered 998, direct references were not provided within the available citations. However, based on similar structures observed in other contests such as those described where configurations often include constraints like `n` representing numbers of elements with defined ranges[^1], it can be inferred that contest or problem 998 would follow a comparable format. Typically, each Codeforces contest includes several problems labeled from A to F or beyond depending on the round size. Each problem comes with its own set of rules, input/output formats, and constraint descriptions. For instance, some problems specify conditions involving integer inputs for calculations or logical deductions, while others might involve more complex algorithms or data processing tasks[^3]. To find detailed information regarding contest or problem 998 specifically: - Visit the official Codeforces website. - Navigate through past contests until reaching contest 998. - Review individual problem statements under this contest for precise requirements and examples. Additionally, competitive programming platforms usually provide comprehensive documentation alongside community discussions which serve valuable resources when exploring particular challenges or learning algorithmic solutions[^2]. ```cpp // Example C++ code snippet demonstrating how contestants interact with input/output during competitions #include <iostream> using namespace std; int main() { int n; cin >> n; // Process according to problem statement specifics } ```
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值