当前位置:网站首页>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;
}
边栏推荐
- Docker-compose install mysql
- 分布式事务之 Atomikos 原理和使用(一)
- 从驱动表和被驱动表来快速理解MySQL中的内连接和外连接
- CISP-PTE Zhenti Demonstration
- 最新版MySQL 8.0 的下载与安装(详细教程)
- 2022年比若依更香的开源项目
- Summary of SQL classic interview questions in 2022 (with analysis)
- WeChat payment and payment callback
- The use of Conluce, an online document management system
- net start mysql MySQL service is starting. MySQL service failed to start.The service did not report any errors.
猜你喜欢

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

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

【小程序项目开发 -- 京东商城】uni-app 商品分类页面(下)

pwn-ROP

Programmers make money and practice, teach you how to do paid courses, self-media, paid articles and paid technical courses to make money

mysql basics (4)
![[GO Language Basics] 1. Why do I want to learn Golang and the popularization of GO language entry](/img/ac/80ab67505f7df52d92a206bc3dd50e.png)
[GO Language Basics] 1. Why do I want to learn Golang and the popularization of GO language entry

Mysql8.+学习笔记

It's time to have to learn English, give yourself multiple paths

并发编程复习
随机推荐
MySQL-Explain详解
MySQL的 DDL和DML和DQL的基本语法
Error: npm ERR code EPERM
It's time to have to learn English, give yourself multiple paths
Path dependence: the poor hard science to counter attack breakthrough
[Mysql] CONVERT function
MySql的初识感悟,以及sql语句中的DDL和DML和DQL的基本语法
微信小程序开发学习
Personal blog system (with source code)
75. 颜色分类
排列数字(DAY90)dfs
Teach you to completely uninstall MySQL
MySQL(3)
mysql 时间字段默认设置为当前时间
[详解C语言]一文带你玩转数组
Introduction to Oracle Patch System and Opatch Tool
2022 Pengcheng Cup web
ClickHouse 数据插入、更新与删除操作 SQL
并发编程复习
面试题 17.13. 恢复空格(字典树)