当前位置:网站首页>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;
}
边栏推荐
- ArcGIS batch export layer script
- Summary of decimal point of amount and price at work and pit
- GDAL multiband synthesis tool
- Combat readiness mathematical modeling 31 data interpolation and curve fitting 3
- 工作上对金额价格类小数点的总结以及坑
- NAACL2022:(代码实践)好的视觉引导促进更好的特征提取,多模态命名实体识别(附源代码下载)...
- 秒懂JSONArray和JSONObject的区别和使用
- Combat readiness mathematical modeling 32 correlation analysis 2
- Numpy基本使用
- Login authentication service
猜你喜欢

710. 黑名单中的随机数

【使用yarn运行报错】The engine “node“ is incompatible with this module.

How to mount cloud disks in ECS

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

'教练,我想打篮球!' —— 给做系统的同学们准备的 AI 学习系列小册

常用控件及自定义控件

Electron

备战数学建模30-回归分析2

Matplotlib common operations

Naacl2022: (code practice) good visual guidance promotes better feature extraction, multimodal named entity recognition (with source code download)
随机推荐
【soloπ】adb连接单个多个手机
Practical website recommendations worth collecting for College Students
Naacl2022: (code practice) good visual guidance promotes better feature extraction, multimodal named entity recognition (with source code download)
聊聊 RPA 方向的规划:简单有价值的事情长期坚持做
这才是优美的文件系统挂载方式,亲测有效
Is it safe to open an online stock account? Somebody give me an answer
Pycharm远程连接服务器来跑代码
How to call self written functions in MATLAB
Flex & Bison 开始
Attention meets Geometry:几何引导的时空注意一致性自监督单目深度估计
A remove the underline from the label
Stream常用操作以及原理探索
Heap optimization dijkstra/hash table storage node number
Can wptx64 be uninstalled_ Which software of win10 can be uninstalled
datasets Dataset类(2)
布局管理器~登录界面的搭建实例
Knowledge about the determination coefficient R2 and the relationship with the correlation coefficient
Leaflet load day map
Installation tutorial about origin2019
方程推导:二阶有源带通滤波器设计!(下载:教程+原理图+视频+代码)