TB椰程 TypeBuddy 打字搭子

2023-12 · 5级 · 小杨的幸运数

GESP 标程 · 考级真题 · 代码 · cpp · 难度 5/5 · 共 1157 字

CCF 原卷官方标程 · 字符串、STL、位运算、浮点数 · 本地编译通过

  • 2023-12
  • 字符串

正文

// GESP 2023-12 C++ 5级 编程题 1 · 小杨的幸运数
// 原题:https://oj.yecheng.tv/p/gs2312l5p1
// 官方原卷:https://gesp.ccf.org.cn/101/attach/1599969567965216.pdf
// 题意:小杨认为,所有大于等于的完全平方数都是他的超级幸运数。
// 知识点:字符串、STL、位运算、浮点数
// 参考程序:CCF 原卷官方标程,PDF 抽取后已去行号;本地编译核验通过,供打字练习
// 原卷样例验证:样例验证 2/2 通过
//
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <map>
#include <iostream>
#include <cmath>
using namespace std;
const int N = 1001 * 1001;
const double eps = 1e-8;
bool is_lucky[N + 5];
int next_lucky[N + 5];
void init() {
}
int main() {
    int a, T;
    scanf("%d%d", &a, &T);
    for (int i = 1; i <= N; i ++) {
        int t = int(sqrt(i) + eps);
        if (i >= a && t * t == i)
            is_lucky[i] = 1;
        if (! is_lucky[i])
            continue ;
        for (int j = i + i; j <= N; j += i)
            is_lucky[j] = 1;
    }
    for(int i = N; i; i --)
        next_lucky[i] = is_lucky[i] ? i : next_lucky[i + 1];
    while(T --) {
        int x;
        scanf("%d", &x);
        if (is_lucky[x])
            cout << "lucky" << endl;
        else
            cout << next_lucky[x] << endl;
    }
    return 0;
}

GESP 标程 · 考级真题的其它内容

打字首页 · 英语学习中心 · 词库画廊 · 编程打字 · 指法入门 · 天梯榜 · 数据分析 · 班级课堂 · 关于我们
椰程 TypeBuddy 打字搭子 —— 键盘指法练习 · 单词记忆 · 班级课堂 · 在线 PK