Codeforces Round #270 A. Design Tutorial: Learn from Math【数论/埃氏筛法】
1 second
256 megabytes
standard input
standard output
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.
The only line contains an integer n (12 ≤ n ≤ 106).
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.
12
4 8
15
6 9
23
8 15
1000000
500000 500000
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.
【注意】:埃氏筛法筛素数时,注意开头i*2非i*i(数字大爆int)
【代码】:
#include<bits/stdc++.h>
using namespace std;
int prime[];
void get_prime()
{
prime[]=prime[]=;//0,1非素数
for(int i=;i<=;i++)
{
if(prime[i]==)
for(int j=i*;j<=;j+=i)
prime[j]=;
}
}
int main()
{
int n;
get_prime();
cin>>n;
for(int i=;i<=n;i++)
if( prime[i]&& prime[n-i] )
{
printf("%d %d\n",i,n-i);
return ;
}
return ;
}
筛法
Codeforces Round #270 A. Design Tutorial: Learn from Math【数论/埃氏筛法】的更多相关文章
- codeforces水题100道 第七题 Codeforces Round #270 A. Design Tutorial: Learn from Math (math)
题目链接:http://www.codeforces.com/problemset/problem/472/A题意:给你一个数n,将n表示为两个合数(即非素数)的和.C++代码: #include & ...
- Codeforces Round #270 D Design Tutorial: Inverse the Problem --MST + DFS
题意:给出一个距离矩阵,问是不是一颗正确的带权树. 解法:先按找距离矩阵建一颗最小生成树,因为给出的距离都是最短的点间距离,然后再对每个点跑dfs得出应该的dis[][],再对比dis和原来的mp是否 ...
- cf472A Design Tutorial: Learn from Math
A. Design Tutorial: Learn from Math time limit per test 1 second memory limit per test 256 megabytes ...
- A - Design Tutorial: Learn from Math(哥德巴赫猜想)
Problem description One way to create a task is to learn from math. You can generate some random mat ...
- 【CodeForces 472A】Design Tutorial: Learn from Math
题 题意:给你一个大于等于12的数,要你用两个合数表示出来.//合数指自然数中除了能被1和本身整除外,还能被其他的数整除(不包括0)的数. 分析:我们知道偶数除了2都是合数,给你一个偶数,你减去一个偶 ...
- codeforce A. Design Tutorial: Learn from Math
题意:将一个数拆成两个合数的和, 输出这两个数!(这道题做的真是TMD水啊)开始的时候不知道composite numbers是啥意思,看了3遍才看懂.... 看懂之后又想用素数筛选法来做,后来决定单 ...
- Codeforces Round #270 A~D
Codeforces Round #270 A. Design Tutorial: Learn from Math time limit per test 1 second memory limit ...
- Codeforces Round #270 1001
Codeforces Round #270 1001 A. Design Tutorial: Learn from Math time limit per test 1 second memory l ...
- Codeforces Round #270--B. Design Tutorial: Learn from Life
Design Tutorial: Learn from Life time limit per test 1 second memory limit per test 256 megabytes in ...
随机推荐
- 《Cracking the Coding Interview》——第18章:难题——题目7
2014-04-29 03:05 题目:给定一个词典,其中某些词可能能够通过词典里其他的词拼接而成.找出这样的组合词里最长的一个. 解法:Leetcode上有Word Break这道题,和这题基本思路 ...
- 《数据结构》C++代码 Splay
Splay,伸展树.之所以先写这个课内并不怎么常用的数据结构,是因为本人非常喜欢Splay,我觉得这是非常有美感且灵活的一种平衡树.在此先声明,我的伸展树写法来源于CLJ大牛,基础好的同学可以去他的博 ...
- jsonp、瀑布流布局、组合搜索、多级评论(评论树)、Tornado初识
1.JSONP原理剖析以及实现 1.1 同源策略限制 用django分别建立两个项目,jsonp01和jsonp02,然后再在这两个项目里分别建立一个app,比如名字叫jsonp1.jsonp2:js ...
- python作业:购物车(第二周)
一.作业需求: 1.启动程序后,输入用户名密码后,如果是第一次登录,让用户输入工资,然后打印商品列表 2.允许用户根据商品编号购买商品 3.用户选择商品后,检测余额是否够,够就直接扣款,不够就提醒 4 ...
- HDU 4109 Instrction Arrangement(DAG上的最长路)
把点编号改成1-N,加一点0,从0点到之前任意入度为0的点之间连一条边权为0的边,求0点到所有点的最长路. SPFA模板留底用 #include <cstdio> #include < ...
- HDU 4699 Editor(双向链表)
双向链表直接模拟. 用一个辅助数组maxSum来维护一下前k项中[1,k]的最大和. 因为光标是一格一格的移动,所以每次光标右移的时候动态更新一下即可. 时间复杂度O(n). #include < ...
- PHP7 深入理解
读 PHP7的内核剖析 php7-internal 记录 3 PHP的相关组成 3.1 SAPI php常见的四种运行模式 SAPI:Server Application Programming In ...
- Java常用实体类
System类 访问系统属性 - 遍历 package org.zln.usefulclass.system; import java.util.Properties; /** * Created b ...
- hdu 1535 Invitation Cards (最短路径)
Invitation Cards Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
- 原来Java大数据才是真正的高富帅!
大数据时代,中国IT环境也将面临重新洗牌,不仅仅是企业,更是程序员们转型可遇而不可求的机遇. 国内大多数大型互联网公司的程序员被称作研发工程师,但实际上国内几乎没有研发项目,只能叫做开发.开发程序员的 ...