当前位置:网站首页>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;
}
边栏推荐
- 留念 · 大学时代最后的系统设计图
- Different usage scenarios of subqueries as retrieval tables and the question of whether to add aliases
- Teach you how to design a CSDN system
- 4、nerf(pytorch)
- mysql basics (4)
- Learn FPGA from the underlying structure (6) ---- Distributed RAM (DRAM, Distributed RAM)
- MySQL索引从入门到深入学习
- mysql高阶语句(一)
- MySQL(3)
- 【小程序项目开发 -- 京东商城】uni-app 商品分类页面(下)
猜你喜欢

This article will take you through js to deal with the addition, deletion, modification and inspection of tree structure data

手把手教你设计一个CSDN系统
![[GO语言基础] 一.为什么我要学习Golang以及GO语言入门普及](/img/ac/80ab67505f7df52d92a206bc3dd50e.png)
[GO语言基础] 一.为什么我要学习Golang以及GO语言入门普及

net start mysql MySQL 服务正在启动 . MySQL 服务无法启动。 服务没有报告任何错误。

2022年SQL大厂高频实战面试题(详细解析)

2022 SQL big factory high-frequency practical interview questions (detailed analysis)

解决phpstudy无法启动MySQL服务

PyCharm使用教程(较详细,图+文)

cmd (command line) to operate or connect to the mysql database, and to create databases and tables

留念 · 大学时代最后的系统设计图
随机推荐
JVM面试总结
curl (7) Failed connect to localhost8080; Connection refused
爬虫数据是如何收集和整理的?
G巴士计数(Google Kickstart2014 Round D Problem B)(DAY 89)
2022年比若依更香的开源项目
Basic syntax of MySQL DDL and DML and DQL
MySQL索引从入门到深入学习
[Koltin Flow (2)] The end operator of the Flow operator
[Koltin Flow (1)] Five ways to create flow
Difference between cookie and session
Different lower_case_table_names settings for server ('1') and data dictionary ('0') solution
黄金圈法则:成功者必备的深度思考方法
个人博客系统(附源码)
手把手教你设计一个CSDN系统
从底层结构开始学习FPGA(6)----分布式RAM(DRAM,Distributed RAM)
IDEA的database使用教程(使用mysql数据库)
Mysql8.+学习笔记
[Image processing] Image skeleton extraction based on central axis transformation with matlab code
The Golden Circle Rule: Deep Thinking Methods for Successful People
Oracle补丁体系及Opatch工具介绍