Taxes

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Mr. Funt now lives in a country with a very specific tax laws. The total income of mr. Funt during this year is equal to n (n ≥ 2) burles and the amount of tax he has to pay is calculated as the maximum divisor of n (not equal to n, of course). For example, if n = 6 then Funt has to pay 3 burles, while for n = 25 he needs to pay 5 and if n = 2 he pays only 1 burle.

As mr. Funt is a very opportunistic person he wants to cheat a bit. In particular, he wants to split the initial n in several parts n1 + n2 + ... + nk = n (here k is arbitrary, even k = 1 is allowed) and pay the taxes for each part separately. He can't make some part equal to 1 because it will reveal him. So, the condition ni ≥ 2 should hold for all i from 1 to k.

Ostap Bender wonders, how many money Funt has to pay (i.e. minimal) if he chooses and optimal way to split n in parts.

Input

The first line of the input contains a single integer n (2 ≤ n ≤ 2·109) — the total year income of mr. Funt.

Output

Print one integer — minimum possible number of burles that mr. Funt has to pay as a tax.

Examples
Input
4
Output
2
Input
27
Output
3

【分析】给你一个数n,让你分成k个大于1的数,没个数取他们的最大因子,可以是1但不可以是本身,求最小的因子和。显然如果分成k个
质数的和,那么答案就是k.根据哥德巴赫猜想,任何一个偶数都可以写成两个质数的和,所以对于偶数(除了2),答案就是2,对于质数,
答案就是1,对于非质数的奇数,若可写成2+质数,答案就是2,否则3.
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#define inf 2e9
#define met(a,b) memset(a,b,sizeof a)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
typedef long long ll;
using namespace std;
const int N = 1e5+;
const int M = 4e5+;
int dp[N][];
int n,sum[N],m=,p,k;
int Tree[N];
bool isprime(ll n){
if(n<=)return false;
if(n==)return true;
else if(n%==)return false;
for(int i=;(ll)i*i<=n;i+=)if(n%i==)return false;
return true;
}
int main()
{
ll q;
scanf("%lld",&q);
if(isprime(q))puts("");
else {
if(q%==)puts("");
else {
if(isprime(q-))puts("");
else puts("");
}
}
return ;
}
 

code forces 382 D Taxes(数论--哥德巴赫猜想)的更多相关文章

  1. CodeForces - 735D Taxes (哥德巴赫猜想)

    Taxes time limit per test 2 seconds memory limit per test 256 megabytes input standard input output ...

  2. Codeforces 735D:Taxes(哥德巴赫猜想)

    http://codeforces.com/problemset/problem/735/D 题意:给出一个n,这个n可以分解成 n = n1 + n2 + -- + nk,其中k可以取任意数.要使得 ...

  3. Codeforces Round #382 (Div. 2) D. Taxes 哥德巴赫猜想

    D. Taxes 题目链接 http://codeforces.com/contest/735/problem/D 题面 Mr. Funt now lives in a country with a ...

  4. CF735D Taxes 哥德巴赫猜想\判定素数 \进一步猜想

    http://codeforces.com/problemset/problem/735/D 题意是..一个数n的贡献是它的最大的因子,这个因子不能等于它本身 然后呢..现在我们可以将n拆成任意个数的 ...

  5. ural 1356. Something Easier(数论,哥德巴赫猜想)

    1356. Something Easier Time limit: 1.0 secondMemory limit: 64 MB “How do physicists define prime num ...

  6. Codefroces 735D Taxes(哥德巴赫猜想)

    题目链接:http://codeforces.com/problemset/problem/735/D 题目大意:给一个n,n可以被分解成n1+n2+n3+....nk(1=<k<=n). ...

  7. D. Taxes 哥德巴赫猜想

    http://codeforces.com/contest/735/problem/D 这题其实我还不是很懂,那个只是猜想,然而却用了. 只想说说找到第一小于n的素数这种思路是不行的. 121 = 1 ...

  8. Codeforces735D Taxes(哥德巴赫猜想)

    题意:已知n元需缴税为n的最大因子x元.现通过将n元分成k份的方式来减少缴税.问通过这种处理方式需缴纳的税费. 分析: 1.若n为素数,不需分解,可得1 2.若n为偶数,由哥德巴赫猜想:一个大于2的偶 ...

  9. *CF2.D(哥德巴赫猜想)

    D. Taxes time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...

随机推荐

  1. DotNetBar for Windows Forms 12.1.0.0_冰河之刃重打包版 原创发布

    关于 DotNetBar for Windows Forms 12.1.0.0_冰河之刃重打包版 --------------------11.8.0.8_冰河之刃重打包版-------------- ...

  2. shared_ptr:资源管理利器

    如果你还在使用传统的C++,那么可以肯定堆内存的管理让你头痛过!在传统的C++领域,堆内存管理上我们能借用的现成工具就只有auto_ptr.但是很不幸用auto_ptr管理堆内存简直就是个错误.aut ...

  3. 使用CSS3各个属性实现小人的动画

    使用CSS3各个属性实现带有音乐小人的动画,完全不使用JS代码: 注:chrome浏览器效果最佳,最终效果静态图: HTML代码如下: <!DOCTYPE html> <html&g ...

  4. 学习Excel 十大函数

    云课堂视频教程 笔记总结: URL:http://study.163.com/course/courseLearn.htm?courseId=1009026#/learn/video?lessonId ...

  5. 软件分析(Mobile Apps )--百词斩

    1) 此类软件是什么时候开始出现的, 这些软件是怎么说服你(陌生人)成为他们的用户的? 他们的目标都是盈利么? 他们的目标都是赚取用户的现金么?还是别的? 2) 你个人第一次用此类软件是什么时候,你当 ...

  6. silverlight导出excel

    开发导出excel,首先需要添加项目引用. Microsoft.CSharp 这个是应用dynamic的前提. 在代码页,需要添加引用 using System.Runtime.InteropServ ...

  7. Python的平凡之路(21)

    上节内容回顾:1.请求周期url> 路由 > 函数或类 > 返回字符串或者模板语言?Form表单提交:    提交 -> url > 函数或类中的方法     - ... ...

  8. @font-face 的用法

    现在很多设计用的字体都是五花八门的.我们切图又不能很好的让搜索爬虫搜索.就会使用@font-face方法: @Font-face目前浏览器的兼容性: Webkit/Safari(3.2+):TrueT ...

  9. 《C++primer》v5 第8章 IO库 读书笔记 习题答案

    8.1.8.2 这一章不咋会啊.. istream &read(istream &is) { int a; auto old_state=is.rdstate(); is.clear( ...

  10. ASP利用Recordset实现分页

    <!--#INCLUDE FILE="../function/db.asp" --> <!--#INCLUDE FILE="../function/co ...