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 ...
随机推荐
- python 学习分享-实战篇高级的ftp
#server代码 import socketserver,os,hashlib Base_paht = os.path.dirname(os.path.dirname(os.path.abspath ...
- PHP基础壹
<?php //<!--//注释方式-->//<!--//echo 后面跟字符串:-->//<!--print("123");-->//& ...
- ZOJ 3717 Balloon ( TLE )
正解2-SAT. 我用DLX想搜一搜的,结果TLE了…… 没什么遗憾,最起码我尝试过了. 扔个代码留作纪念. #include <cstdio> #include <cstring& ...
- 【PHP】- 启用CRUL和GD
1.修改php.ini文件,确保extension_dir配置为php目录的ext,如图: 2.修改php.ini文件,将以下两项取消注释: 3.将php目录下的 libeay32.dll 和 lib ...
- EXTJS4.0 form 表单提交 后 回调函数 不响应的问题
在提交表单后,应返回一个 JSON 至少要包含{success:true} 否则,EXT 不知道是否成功,没有响应. {success:true,msg:'成功',Url:'http://www.ba ...
- 【bzoj3675】[Apio2014]序列分割 斜率优化dp
原文地址:http://www.cnblogs.com/GXZlegend/p/6835179.html 题目描述 小H最近迷上了一个分隔序列的游戏.在这个游戏里,小H需要将一个长度为n的非负整数序列 ...
- LeetCode -- Construct Binary Tree from Preorder and Inorder
Question: Given preorder and inorder traversal of a tree, construct the binary tree. Note:You may as ...
- BZOJ 4326 NOIP2015 运输计划(树上差分+LCA+二分答案)
4326: NOIP2015 运输计划 Time Limit: 30 Sec Memory Limit: 128 MB Submit: 1388 Solved: 860 [Submit][Stat ...
- nginx+php-fpm配置后页面显示空白的解决方法以及用nginx和php-fpm解决“502 Bad Gateway”问题
For reference, I am attaching my location block for catching files with the .php extension: location ...
- CF10D LCIS (动态规划)
题目链接 Solution 动态规划. 令 \(f_{i,j}\) 表示 \(a\) 数组前 \(i\) 个和 \(b\) 数组前 \(j\) 所得的最长的 LCIS . 转移很好想: \(a_i!= ...