博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Acm Dima and Lisa的题解
阅读量:7032 次
发布时间:2019-06-28

本文共 1793 字,大约阅读时间需要 5 分钟。

D. Dima and Lisa time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output Dima loves representing an odd number as the sum of multiple primes, and Lisa loves it when there are at most three primes. Help them to represent the given number as the sum of at most than three primes.

More formally, you are given an odd numer n. Find a set of numbers pi (1?≤?i?≤?k), such that

1?≤?k?≤?3 pi is a prime

The numbers pi do not necessarily have to be distinct. It is guaranteed that at least one possible solution exists.

Input The single line contains an odd number n (3?≤?n?<?109).

Output In the first line print k (1?≤?k?≤?3), showing how many numbers are in the representation you found.

In the second line print numbers pi in any order. If there are multiple possible solutions, you can print any of them.

Examples input 27 output 3 5 11 11

 

http://codeforces.com/problemset/problem/584/D

 

 

题意不难理解  可是还是有一点坑点的  我本来是两个for循环直接暴力的   可是这样会有bug   后来想到了哥德巴赫猜想   大于6的偶数都能分解为两个奇质数之和

所以除了3 4 5    其他的数    偶数的话  就先搞个2出来   奇数就先搞个3    剩下的数就一定可以分解了 

#include
#include
#include
#include
#include
#include
using namespace std;long long ans[5];int zhishu(long long n){ for(int i=2;i<=sqrt(n);i++){ if(n%i==0) return 0; } return 1; }//哥德巴赫猜想耶~~~ 好神奇呀 int main(){ long long n; scanf("%lld",&n); if(n>=6){ if(n%2==0) ans[1]=2; else ans[1]=3; for(int i=2;i<=n-ans[1];i++){ if(zhishu(i)==1&&zhishu(n-ans[1]-i)==1){ ans[2]=i; ans[3]=n-ans[1]-i; printf("3\n%lld %lld %lld\n",ans[1],ans[2],ans[3]); return 0; } if(i>2) i++; } } else{ if(n==3) printf("1\n%lld\n",n); else if(n==4||n==5){ n=n-2; printf("2\n2 %lld\n",n); } } }

 

转载于:https://www.cnblogs.com/irrelevant/p/5514470.html

你可能感兴趣的文章
记Promise得一些API
查看>>
javascript事件之调整大小(resize)事件
查看>>
20145234黄斐《Java程序设计》第六周学习总结
查看>>
【CLRS】《算法导论》读书笔记(四):栈(Stack)、队列(Queue)和链表(Linked List)...
查看>>
hibernate 和 mybatis区别
查看>>
互联网广告综述之点击率特征工程
查看>>
HDU3421 Max Sum II【序列处理】
查看>>
POJ NOI MATH-7653 地球人口承载力估计
查看>>
iOS UI高级之网络编程(HTTP协议)
查看>>
使用cocoaPods import导入时没有提示的解决办法
查看>>
iOS数据持久化存储之归档NSKeyedArchiver
查看>>
JavaScript面向对象
查看>>
Intellij修改模板代码
查看>>
2.页面布局示例笔记
查看>>
一些老游戏CPU 100%占用的解决方法
查看>>
f5基本介绍
查看>>
博前语
查看>>
Java SE核心之一:常用类,包装类,其他基本数据类型包装类。
查看>>
郑捷《机器学习算法原理与编程实践》学习笔记(第二章 中文文本分类(一))...
查看>>
python (ploit)
查看>>