当前位置:网站首页>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;
}
边栏推荐
- GDAL and opencv smooth and blur TIF images
- GDAL grid data types and their type codes
- BM3D in popular language
- Practice with the topic of bit operation force deduction
- Leaflet load day map
- 信息学奥赛一本通 1400:统计单词数 (字符串匹配)
- 券商经理给的开户链接安全吗?找谁可以开户啊?
- 使用 Abp.Zero 搭建第三方登录模块(一):原理篇
- MySQL master-slave replication and read-write separation
- 'coach, I want to play basketball!'—— AI Learning Series booklet for system students
猜你喜欢

The engine "node" is inconsistent with this module

STM32F1和GD32F1有什么区别?

数学建模经验分享:国赛美赛对比/选题参考/常用技巧

详解C语言编程题:任意三条边能否构成三角形,输出该三角形面积并判断其类型

Related knowledge of libsvm support vector machine

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

Login authentication service

This is the graceful file system mounting method, which is effective through personal testing

Chinese output of PostGIS console is garbled

使用 Abp.Zero 搭建第三方登录模块(二):服务端开发
随机推荐
Is it safe to open an online stock account? Somebody give me an answer
Pycharm远程连接服务器来跑代码
挖财注册开户安全吗,有没有什么风险?
Sword finger offer 21.57.58 I Double pointer (simple)
Difference between classification and regression
Electron
券商经理给的开户链接办理股票开户安全吗?我想开个户
2021-10-29 atcoder ABC157——B - Bingo
Related knowledge of libsvm support vector machine
权威发布 | 延安大学2022年教师岗位招聘公告
[solo π] ADB connects multiple mobile phones
Server create virtual environment run code
年薪50万是一条线,年薪100万又是一条线…...
JVM 输出 GC 日志导致 JVM 卡住,我 TM 人傻了
Matplotlib common operations
方程推导:二阶有源带通滤波器设计!(下载:教程+原理图+视频+代码)
Introduction to basic knowledge of C language (Daquan) [suggestions collection]
This is the graceful file system mounting method, which is effective through personal testing
Mathematical modeling of war preparation 30 regression analysis 2
Oracle11g database import and export method tutorial [easy to understand]