当前位置:网站首页>Prime numbers (Tsinghua University computer test questions) (DAY 86)
Prime numbers (Tsinghua University computer test questions) (DAY 86)
2022-07-30 06:06:00 【Zhang Xueheng】
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;
}
边栏推荐
- Within the SQL connection table (link connections, left or right, cross connection, full outer join)
- 839. Simulated heap
- IDEA的database使用教程(使用mysql数据库)
- Path dependence: the poor hard science to counter attack breakthrough
- [其他] DS5
- JVM之GC 调优工具 Arthas 实战使用(二)
- Different lower_case_table_names settings for server (‘1‘) and data dictionary (‘0‘) 解决方案
- Teach you how to design a CSDN system
- postman 请求 post 调用 传 复合 json数据
- 使用DataEase开源工具制作一个高质量的数据大屏
猜你喜欢
More fragrant open source projects than Ruoyi in 2022
MySQL 灵魂 16 问,你能撑到第几问?
navicat新建数据库
Nacos 原理
从字节码角度带你彻底理解异常中catch,return和finally,再也不用死记硬背了
[GO Language Basics] 1. Why do I want to learn Golang and the popularization of GO language entry
2022年SQL大厂高频实战面试题(详细解析)
MySql string splitting realizes the split function (field splitting, column switching, row switching)
号称年薪30万占比最多的专业,你知道是啥嘛?
Redis学习
随机推荐
[其他] DS5
解决没有配置本地nacos但是一直发生localhost8848连接异常的问题
MySQL (2)
php数组实现根据某个键值将相同键值合并生成新二维数组的方法
Countdown (Source: Google Kickstart2020 Round C Problem A) (DAY 88)
An old programmer's summary review of 2020, how to become more awesome in 2021
mysql basics (4)
MySql fuzzy query Daquan
JVM 类加载机制 超详细学习笔记(三)
IDEA的database使用教程(使用mysql数据库)
asyncawait和promise的区别
mysql 时间字段默认设置为当前时间
MySQL索引从入门到深入学习
微信小程序开发学习
[GO语言基础] 一.为什么我要学习Golang以及GO语言入门普及
[GStreamer] 插件的名字要和GST_PLUGIN_DEFINE匹配
MySQL 数据库基础知识(系统化一篇入门)
Path dependence: the poor hard science to counter attack breakthrough
Error: npm ERR code EPERM
【飞控开发基础教程9】疯壳·开源编队无人机-PWM(电机控制)