首页 > 其他分享 > 谷歌的招聘

谷歌的招聘

时间:2022-08-22 19:56:21浏览次数:43  
标签:cnt 招聘 int 质数 谷歌 st bool primes

https://www.acwing.com/problem/content/1648/

思路:
如果单纯的用试除法去做,可能会超时,我们在这里先弄出来根号内的所有质数,然后用质数来做。

#include <iostream>
#include <cstring>

using namespace std;

const int N = 1010, M = 40000;

int n, k;
bool st[M];
int primes[M], cnt;

void init()
{
    for (int i = 2; i < M; i ++ )
        if (!st[i])
        {
            primes[cnt ++ ] = i;
            for (int j = i * 2; j < M; j += i)
                st[j] = true;
        }
}

bool check(int x)
{
    for (int i = 0; primes[i] <= x / primes[i]; i ++ )
        if (x % primes[i] == 0)
            return false;
    return true;
}

int main()
{
    init();

    string str;
    cin >> n >> k >> str;

    for (int i = 0; i + k <= n; i ++ )
    {
        int t = stoi(str.substr(i, k));
        if (check(t))
        {
            cout << str.substr(i, k) << endl;
            return 0;
        }
    }

    puts("404");

    return 0;
}

标签:cnt,招聘,int,质数,谷歌,st,bool,primes
From: https://www.cnblogs.com/xjtfate/p/16614046.html

相关文章

  • 谷歌应用商店
    当然,你也可以用浙江大学的镜像https://g.luciaz.me验证答案是:心灵之约|水朝夕|csxy@123 只能用搜索吗可以访问谷歌应用商店吗   https:......
  • 备份谷歌或其他浏览器插件
    原文链接备份谷歌或其他浏览器插件1浏览器地址栏输入:chrome://extensions/,选择开发模式,单击打包扩展程序,可以看到一个“扩展程序根目录”输入框。2进入浏览器插件的......
  • 2022年谷歌Chrome等浏览器在线打开编辑保存微软Office/金山WPS的Word、Excel和PPT技术
    一、行业背景长久以来,在IE、Chrome45及Firefox53以下版本的浏览器网页中,可直接或间接调用微软免费开源的ActiveX控件DsoFramer或参考DsoFramer实现的一些收费NPAPI办公......