当前位置:网站首页>质数(清华大学机试题)(DAY 86)
质数(清华大学机试题)(DAY 86)
2022-07-30 05:26:00 【张学恒】
1:题目
给定一个正整数 X,请你在 X 后面添加若干位数字(至少添加一位数字;添加的数不能有前导0),使得结果为质数,在这个前提下所得的结果应尽量小。
输入格式
第一行包含一个整数 T,表示共有 T 组测试数据。
每组数据占一行,包含一个整数 X。
输出格式
每组数据输出一行结果,一个整数,表示所得的满足条件的最小质数。
数据范围
1≤T≤100,
1≤X≤100。
输入样例:
1
1
输出样例:
11
难度:简单
时/空限制:1s / 64MB
总通过数:815
总尝试数:1961
来源:清华大学考研机试题
算法标签
2:代码实现
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
bool is_prime(int x)
{
if (x < 2) return false;
for (int i = 2; i * i <= x; i ++ )
if (x % i == 0)
return false;
return true;
}
int main()
{
int T;
cin >> T;
while (T -- )
{
int x;
cin >> x;
for (int i = 1;; i ++ )
{
string str = to_string(x) + to_string(i);
int y = stoi(str);
if (is_prime(y))
{
cout << y << endl;
break;
}
}
}
return 0;
}
边栏推荐
- Hexagon_V65_Programmers_Reference_Manual (14)
- 分布式事务之 Atomikos 原理和使用(一)
- Codeforces Round #809 (Div. 2) A~D
- 【LeetCode】Day107-除自身以外数组的乘积
- 2022鹏城杯web
- It's time to have to learn English, give yourself multiple paths
- Acwing perfect number
- 一文带你吃透js处理树状结构数据的增删改查
- 倒计数(来源:Google Kickstart2020 Round C Problem A)(DAY 88)
- Hexagon_V65_Programmers_Reference_Manual (11)
猜你喜欢

How MySQL to prepare SQL pretreatment (solve the query IN SQL pretreatment can only query out the problem of a record)

The Golden Circle Rule: Deep Thinking Methods for Successful People

上交所行情文件解析之mktdt04

黄金圈法则:成功者必备的深度思考方法

Summary of skills in using ms project2010 project management software

容器化 | 在 K8s 上部署 RadonDB MySQL Operator 和集群

最新版MySQL 8.0 的下载与安装(详细教程)

Participate in open source, let programmers regain their blood and passion

五一去见了一些身价数千万的成功人士,我一些新的思路和启示

pycharm上的tensorflow环境搭载
随机推荐
MySQL索引常见面试题(2022版)
MySQL - 函数及约束命令
pycharm上的tensorflow环境搭载
Codeforces Round #809 (Div. 2) A~D
并发编程复习
Kyligence 亮相第五届南方信息大会并获评“CIO 优选数字化服务商”
An old programmer's summary review of 2020, how to become more awesome in 2021
工具 | 常用 PostgreSQL 预防数据丢失方案
MySQL(3)
Hexagon_V65_Programmers_Reference_Manual (12)
从字节码角度带你彻底理解异常中catch,return和finally,再也不用死记硬背了
参与开源,让程序员找回热血和激情
C语言中的基本库函数(qsort)
108. 将有序数组转换为二叉搜索树
Internet (software) company project management software research report
MySQL - Function and Constraint Commands
Within the SQL connection table (link connections, left or right, cross connection, full outer join)
nacos-2.0.3启动报错出现no datasource set的坑
IDEA的database使用教程(使用mysql数据库)
"Hou Lang" programmer version, a speech dedicated to a new generation of programmers, He Bing's "Hou Lang" speech imitation show