当前位置:网站首页>质数(清华大学机试题)(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;
}
边栏推荐
- 无代码开发平台重新申请入门教程
- 丑陋的程序员
- pytorch官网中如何选择以及后面的安装和pycharm测试步骤
- MySql string splitting realizes the split function (field splitting, column switching, row switching)
- 一文带你吃透js处理树状结构数据的增删改查
- 力扣1047-删除字符串中的所有相邻重复项——栈
- Acwing perfect number
- Programmers care guide, give yourself a chance to make the occasional relaxation of body and mind
- RadonDB PostgreSQL on K8s 2.1.0 发布!
- C language implements highly secure game archives and reads files
猜你喜欢
JVM 类加载机制 超详细学习笔记(三)
Kyligence 出席华为全球智慧金融峰会,加速拓展全球市场
This article will take you through js to deal with the addition, deletion, modification and inspection of tree structure data
MySQL基础(DDL、DML、DQL)
Us to raise interest rates by 75 basis points in "technical recession"?Encryption market is recovering
MySQL索引常见面试题(2022版)
IDEA的database使用教程(使用mysql数据库)
mysql高阶语句(一)
力扣05-替换空格——字符串问题
ugly programmer
随机推荐
Concurrent Programming Review
MySQL kills 10 questions, how many questions can you stick to?
go版本升级
即刻报名|前沿技术探索:如何让 Spark 更强劲、更灵活
curl (7) Failed connect to localhost8080; Connection refused
力扣05-替换空格——字符串问题
无代码开发平台重新申请入门教程
翻译 | 解读首部 Kubernetes 纪录片
Programmers make money and practice, teach you how to do paid courses, self-media, paid articles and paid technical courses to make money
MySQL如何对SQL做prepare预处理(解决IN查询SQL预处理仅能查询出一条记录的问题)
[Redis Master Cultivation Road] Jedis - the basic use of Jedis
el-table中加入el-input框和el-input-number框,实现el-table的可编辑功能
839. 模拟堆
(Hexagon_V65_Programmers_Reference_Manual(13)
ThinkPHP high imitation blue play cloud network disk system source code / docking easy payment system program
Acwing perfect number
【LeetCode】Day107-除自身以外数组的乘积
go language study notes 2
ugly programmer
oracle触发器的自治事务