D. 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 partsn1 + 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拆成若干的数(不能拆成1,可以不拆),每个数得到的花费是他的最大约数(不包括自己),问花费最小是多少
我们很容易想到尽可能把每个数拆成较少的素数,这样的花费。根据哥德巴赫猜想,任意一个大于2的偶数一定能拆成两个素数的和。
而一个奇数又能拆成一个奇数和一个偶数,所以对于大于2的数而言,如果是素数,输出1,如果是偶数输出2名如果是奇数,我们要
讨论n-2是不是素数,如果是输出2,否则输出3;

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std; bool is(int x)
{
if(x==0||x==1)
return 0;
if(x==2)
return 1;
for(int i=2;i<=sqrt(x);i++)
{
if(x%i==0)
return 0;
}
return 1;
}
int main()
{
long long n;
while(~scanf("%I64d",&n))
{
if(is(n))
printf("1\n");
else
{
if(n%2)
{
if(is(n-2))
printf("2\n");
else
printf("3\n");
}
else
printf("2\n");
}
}
return 0;
}

Codeforces735D Taxes 2016-12-13 12:14 56人阅读 评论(0) 收藏的更多相关文章

  1. iOS纯代码手动适配 分类: ios技术 2015-05-04 17:14 239人阅读 评论(0) 收藏

    首先说下让自己的程序支持iPhone6和6+,第一种使用官方提供的launch screen.xib,这个直接看官方文档即可,这里不再多述:第二种方法是和之前iPhone5的类似,比较简单,为iPho ...

  2. POJ2195 Going Home (最小费最大流||二分图最大权匹配) 2017-02-12 12:14 131人阅读 评论(0) 收藏

    Going Home Description On a grid map there are n little men and n houses. In each unit time, every l ...

  3. HDU2212 DFS 2016-07-24 13:52 56人阅读 评论(0) 收藏

    DFS Problem Description A DFS(digital factorial sum) number is found by summing the factorial of eve ...

  4. ArcGIS for Server的安装及站点中的集群配置 分类: ArcGIS for server 2015-07-18 14:14 16人阅读 评论(0) 收藏

       坚信并为之坚持是一切希望的原因. (不足之处,欢迎批评指正!) --------------------环境:Windows server2008R2虚拟机两台----------------- ...

  5. Curling 2.0 分类: 搜索 2015-08-09 11:14 3人阅读 评论(0) 收藏

    Curling 2.0 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 14289 Accepted: 5962 Descript ...

  6. winform timespan 两个时间的间隔(差) 分类: WinForm 2014-04-15 10:14 419人阅读 评论(0) 收藏

    TimeSpan 结构  表示一个时间间隔. 先举一个小例子:(计算两个日期相差的天数) 代码如下: DateTime dt = DateTime.Now.ToShortDateString(yyyy ...

  7. HRBUST1315 火影忍者之~大战之后 2017-03-06 16:14 54人阅读 评论(0) 收藏

    火影忍者之-大战之后 经历了大战的木叶村现在急需重建,人手又少,所以需要尽可能多的接受外来的任务,以赚取报酬,重建村庄,假设你现在是木叶的一名高级忍者,有一大堆的任务等着你来做,但毕竟个人时间有限,所 ...

  8. hdu1158 Employment Planning 2016-09-11 15:14 33人阅读 评论(0) 收藏

    Employment Planning Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Othe ...

  9. Gora官方范例 分类: C_OHTERS 2015-01-29 16:14 632人阅读 评论(0) 收藏

    参考官方文档:http://gora.apache.org/current/tutorial.html 项目代码见:https://code.csdn.net/jediael_lu/mygoradem ...

随机推荐

  1. How a non-windowed component can receive messages from Windows

    Why do it? Sometimes we need a non-windowed component (i.e. one that isn't derived fromTWinControl) ...

  2. MVC3 发布到IIS 7.5

    1.应用程序池采用集成模式(建议),.NET Framework版本为: .NET Framework4.0.30319. 2.确保ASP.NET MVC3已安装好,然后检查站点的处理程序映射,看是否 ...

  3. toString方法的用法

    public class JLDtoS {   public static void main(String[]args)   {    long a=123;    Long aa=new Long ...

  4. TZOJ 5280 搜索引擎(模拟字符串)

    描述 谷歌.百度等搜索引擎已经成为了互连网中不可或缺的一部分.在本题中,你的任务也是设计一个搜索论文的搜索引擎,当然,本题的要求比起实际的需求要少了许多. 本题的输入将首先给出一系列的论文,对于每篇论 ...

  5. [leetcode]173. Binary Search Tree Iterator 二叉搜索树迭代器

    Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the ro ...

  6. 嵌入式的SQL程序设计

    嵌入式的SQL程序设计 sql语句大全之嵌入式SQL 2017-01-18 16:00 来源:未知   嵌入式SQL 为了更好的理解嵌入式SQL,本节利用一个具体例子来说明.嵌入式SQL允许程序连接数 ...

  7. HDFS高可用性及其分布式系统思想基础

    源自单点失效问题,也就是当NameNode不可用的时候,用什么办法可以平滑过渡? 最直接的办法是再添加一个备用的NN,这就产生了Active NameNode和Standby NameNode的设计思 ...

  8. BZOJ2424 [HAOI2010]订货 - 费用流

    题解 (非常裸的费用流 题意有一点表明不清: 该月卖出的商品可以不用算进仓库里面. 然后套上费用流模板 代码 #include<cstring> #include<queue> ...

  9. python基础之删除文件及删除目录的方法-乾颐堂

    下面来看一下python里面是如何删除一个文件及文件夹的~~ 首先引入OS模块 import os 删除文件: os.remove() 删除空目录: os.rmdir() 递归删除空目录: os.re ...

  10. 使用phpExcel导出excel文件

    function export($log_list_export) { require "../include/phpexcel/PHPExcel.php"; require &q ...