A - Design Tutorial: Learn from Math(哥德巴赫猜想)
Problem description
One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that.
For example, there is a statement called the "Goldbach's conjecture". It says: "each even number no less than four can be expressed as the sum of two primes". Let's modify it. How about a statement like that: "each integer no less than 12 can be expressed as the sum of two composite numbers." Not like the Goldbach's conjecture, I can prove this theorem.
You are given an integer n no less than 12, express it as a sum of two composite numbers.
Input
The only line contains an integer n (12 ≤ n ≤ 106).
Output
Output two composite integers x and y (1 < x, y < n) such that x + y = n. If there are multiple solutions, you can output any of them.
Examples
Input
12
15
23
1000000
Output
4 8
6 9
8 15
500000 500000
Note
In the first example, 12 = 4 + 8 and both 4, 8 are composite numbers. You can output "6 6" or "8 4" as well.
In the second example, 15 = 6 + 9. Note that you can't output "1 14" because 1 is not a composite number.
解题思路:每个不小于12的整数可以表示为两个合成数之和,若满足条件有多组,则输出其中的一组,简单判断即可。
AC代码:
#include<bits/stdc++.h>
using namespace std;
bool isprime(int x){
for(int i=;i*i<=x;++i)
if(x%i==)return false;
return true;
}
int main(){
int n;cin>>n;
for(int i=;;i+=)
if(!isprime(n-i)){cout<<i<<' '<<(n-i)<<endl;break;}
return ;
}
最新文章
- 查询java 类加载的路径
- Dijkstra搜索算法
- PHP学习第一天笔记——php的基本语法
- Effective Java Index
- S3C2440 裸机程序之音频
- step by step 之餐饮管理系统四(日志模块实现)
- spring boot学习
- UITextView的字数限制 及 添加自定义PlaceHolder
- User_Agent_List 浏览器信息列表
- 通过点击取消按钮关闭dialog窗口
- [算法导论]贪心算法(greedy algorithm)
- C# 静态类与非静态类、静态成员的区别分析
- ES6笔记① var 和 let的区别
- 四核网络机顶盒芯片局势分析(开放市场):rk3128将会成为四核主流
- 17.1.1.7 Setting Up Replication with New Master and Slaves 设置复制对于新的Master和Slaves:
- Javascript多线程引擎(五)
- 开源一个上架 App Store 的相机 App
- 一个比Spring Boot快44倍的Java框架!
- php算法题2
- 好用的 over the wall教程