当前位置:网站首页>Informatics Olympiad 1405: sum and product of prime numbers (thinking problem)
Informatics Olympiad 1405: sum and product of prime numbers (thinking problem)
2022-06-26 14:47:00 【GHOSTANDBREAD】
Information Science Olympiad all in one (C++ edition ) Online evaluation system (ssoier.cn)
【 Title Description 】
The sum of two prime numbers is S, What is the maximum product of them ?
【 Input 】
One is not greater than 10000 The positive integer S, Is the sum of two prime numbers .
【 Output 】
An integer , Is the maximum product of two prime numbers . The data is guaranteed to have a solution .
【 sample input 】
50【 sample output 】
589Ideas :
A number is divided into two parts , How to maximize the product , for example :50 Split into 1 and 49 as well as 50 Split into 25 and 25, Obviously, the closer these two numbers are to the middle , The bigger the product , The problem is that these two prime numbers can be the same , But the title doesn't say .
Code :
#include<iostream>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
bool flag = false;
bool isprime(int x) {
if(x == 1) return false;
for(int i = 2; i <= x / i; i ++) {
if(x % i == 0) return false;
}
return true;
}
int main() {
ios::sync_with_stdio(false);
cout.tie(nullptr);
int x;
cin >> x;
int h = x / 2;
for(int i = h; i <= x; i ++) {
for(int j = i; j >= 0; j --) {
if(isprime(i) && isprime(j) && i + j == x) {
cout << i * j;
flag = true;
break;
}
}
if(flag) break;
}
return 0;
}
边栏推荐
- How to convert data in cell cell into data in matrix
- 备战数学建模30-回归分析2
- Leaflet loading ArcGIS for server map layers
- Extended hooks
- VMware partial settings
- Datasets dataset class (2)
- 详解C语言编程题:任意三条边能否构成三角形,输出该三角形面积并判断其类型
- wptx64能卸载吗_win10自带的软件哪些可以卸载
- 启动Redis报错:Could not create Server TCP listening socket *:6379: bind: Address already in use–解决办法
- fileinput. js php,fileinput
猜你喜欢

Complimentary Book Cognitive Control: how does our brain accomplish tasks?

Where do people get their top energy?

Sword finger offer 21.57.58 I Double pointer (simple)

使用 Abp.Zero 搭建第三方登录模块(二):服务端开发

Deploy the flask environment using the pagoda panel

The engine "node" is inconsistent with this module

Login authentication service

Leaflet load day map

获取两个dataframe的交并差集

MySQL主从复制与读写分离
随机推荐
The JVM outputs GC logs, causing the JVM to get stuck. I am stupid
BM3D in popular language
The engine "node" is inconsistent with this module
信息学奥赛一本通 1405:质数的和与积 (思维题)
Flex & bison start
【云原生】 ”人人皆可“ 编程的无代码 iVX 编辑器
Summary of decimal point of amount and price at work and pit
D - Face Produces Unhappiness
通俗语言说BM3D
获取两个dataframe的交并差集
The annual salary of 500000 is one line, and the annual salary of 1million is another line
GDAL and opencv smooth and blur TIF images
【async/await】--异步编程最终解决方案
Unity 利用Skybox Panoramic着色器制作全景图预览有条缝隙问题解决办法
Electron
Pychar remotely connects to the server to run code
wptx64能卸载吗_win10自带的软件哪些可以卸载
数学建模经验分享:国赛美赛对比/选题参考/常用技巧
Go变量的声明与赋值
H5关闭当前页面,包括微信浏览器(附源码)