【CodeForces - 472A】Design Tutorial: Learn from Math (tricks,思维,数论,打表)
题干:
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
Output
4 8
Input
15
Output
6 9
Input
23
Output
8 15
Input
1000000
Output
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的整数,让你分解成两个合数。
解题报告:
看似不显然,,但是其实很显然啊,如果是偶数那就输出4和n-4 或者6 和n-6这样的都行。如果是奇数那就输出9 和 n-9。做题的时候傻了吧唧的写了个素数打表。得亏数据给的小是1e6,,要是1e18这样的还真不好办了(不过要是给那样的数据也就回去想规律了2333)。
AC代码:
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define ll long long
#define pb push_back
#define pm make_pair
#define fi first
#define se second
using namespace std;
const int MAX = 2e6 + 5;
bool is[MAX];
void prime() {memset(is,1,sizeof is);is[0]=is[1]=0;for(int i = 2; i<=1000000; i++) {if(is[i]) {for(int j = i+i; j<=1000000; j+=i) is[j]=0; }}
}
int main()
{prime();int n;cin>>n;for(int i = 3; i*2<=n; i++) {if(is[i]==0 && is[n-i] == 0) {printf("%d %d\n",i,n-i);break;}}return 0 ;}
【CodeForces - 472A】Design Tutorial: Learn from Math (tricks,思维,数论,打表)相关推荐
- codeforce A. Design Tutorial: Learn from Math
题意:将一个数拆成两个合数的和, 输出这两个数!(这道题做的真是TMD水啊)开始的时候不知道composite numbers是啥意思,看了3遍才看懂.... 看懂之后又想用素数筛选法来做,后来决定单 ...
- codeforces B. Design Tutorial: Learn from Life
题意:有一个电梯,每一个人都想乘电梯到达自己想要到达的楼层! 从a层到b层的时间是|a-b|, 乘客上下电梯的时间忽略不计!问最少 需要多少的时间.... 这是一道神题啊,自己的思路不知不觉 ...
- codeforces D. Design Tutorial: Inverse the Problem
题意:给定一个矩阵,表示每两个节点之间的权值距离,问是否可以对应生成一棵树, 使得这棵树中的任意两点之间的距离和矩阵中的对应两点的距离相等! 思路:我们将给定的矩阵看成是一个图,a 到 b会有多条路径 ...
- codeforces C. Design Tutorial: Make It Nondeterministic
题意:每一个人 都有frist name 和 last name! 从每一个人的名字中任意选择 first name 或者 last name 作为这个人的编号!通过对编号的排序,得到每一个人 最终顺 ...
- Educational Codeforces Round 90 (Rated for Div. 2)(D 思维 E 打表)
题目链接 D. Maximum Sum on Even Positions 题意:给你n长度的数组a 要求翻转 子区间 使得 偶数上的数之和尽量最大. 做法:用偶数位置减去奇数位置的值 就相当 ...
- Codeforces 914D - Bash and a Tough Math Puzzle 线段树,区间GCD
题意: 两个操作, 单点修改 询问一段区间是否能在至多一次修改后,使得区间$GCD$等于$X$ 题解: 正确思路; 线段树维护区间$GCD$,查询$GCD$的时候记录一共访问了多少个$GCD$不被X整 ...
- Tcl Tutorial 笔记3 ·math
目录 expr Operators 数字上的操作 数学函数 Type conversions 数组 example Example 1 Example 2 未完待续... expr 用于进行数学计算的 ...
- Codeforces 478C Table Decorations【贪心】【思维】
传送门:http://codeforces.com/problemset/problem/478/C 题意:用红绿蓝三种气球装饰桌子,要求每张桌子上的气球不能完全相同,问最多能装饰几张桌子. 分析:如 ...
- codeforces 465 C. No to Palindromes!(暴力+思维)
题目链接:http://codeforces.com/contest/465/problem/C 题意:给出一个不存在2个或以上回文子串的字符串,全是由小写字母组成而且字母下表小于p,问刚好比这个字符 ...
最新文章
- 实施Kubernetes可以实现多云架构安全
- Spark读取普通RDD加载为DataFrame
- python怎么学最快-零基础怎么样才能学好Python?Python入门必看
- mysql查询当天所有数据sql语句
- Python 算法模板库,Pythonista 找工作利器
- HANA report里默认filter的工作机制
- 巧用这19条MySQL优化,效率至少提高3倍
- c++中的运算符重载---知识点:运算符重载函数,友元函数,函数重载
- 20190906:(leetcode习题)Shuffle an Array
- JAVA读取、写入Excel表格(含03版)
- 手把手教学电信天翼校园接入无线路由器(通用版)
- python json格式转换后,中文乱码
- Android-S模拟器
- cattee翻译_0302 echo、重定向、管道、cat、tee
- 如何打开caj文件?能转成PDF吗?
- 移动聚合支付招商,管道收入享长期分润
- 苹果app没删但是桌面找不到
- mysql多表查询分页面_mysql多表联合查询分点经验给大家
- 购买的Microsoft Office不小心卸载后重新安装方法
- java 时间差 long,java计算时间差及比较时间大小
热门文章
- 三元运算符 在数据绑定中的使用
- vue vue的table表格自适应_响应式表格,HTML表格自适应(responsive table)
- PHP统计API调用,php – 记录API调用
- Retrofit的简单使用
- webpack最新版本_webpack小结-开发环境构建优化
- java list 分组_Java 将List中的实体类按照某个字段进行分组并存
- sigquit信号默认忽略吗_老妹儿,你真的搞懂了 Shell 信号吗?
- uboot 的i2c_read
- android+3.0新加的动画,Android动画片
- 香肠派对电脑版_《香肠派对》是不是除了《和平精英》最成功的吃鸡手游:靠恶搞火了?...