Codeforces735D Taxes 2016-12-13 12:14 56人阅读 评论(0) 收藏
2 seconds
256 megabytes
standard input
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.
The first line of the input contains a single integer n (2 ≤ n ≤ 2·109) —
the total year income of mr. Funt.
Print one integer — minimum possible number of burles that mr. Funt has to pay as a tax.
4
2
27
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) 收藏的更多相关文章
- iOS纯代码手动适配 分类: ios技术 2015-05-04 17:14 239人阅读 评论(0) 收藏
首先说下让自己的程序支持iPhone6和6+,第一种使用官方提供的launch screen.xib,这个直接看官方文档即可,这里不再多述:第二种方法是和之前iPhone5的类似,比较简单,为iPho ...
- 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 ...
- 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 ...
- ArcGIS for Server的安装及站点中的集群配置 分类: ArcGIS for server 2015-07-18 14:14 16人阅读 评论(0) 收藏
坚信并为之坚持是一切希望的原因. (不足之处,欢迎批评指正!) --------------------环境:Windows server2008R2虚拟机两台----------------- ...
- 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 ...
- winform timespan 两个时间的间隔(差) 分类: WinForm 2014-04-15 10:14 419人阅读 评论(0) 收藏
TimeSpan 结构 表示一个时间间隔. 先举一个小例子:(计算两个日期相差的天数) 代码如下: DateTime dt = DateTime.Now.ToShortDateString(yyyy ...
- HRBUST1315 火影忍者之~大战之后 2017-03-06 16:14 54人阅读 评论(0) 收藏
火影忍者之-大战之后 经历了大战的木叶村现在急需重建,人手又少,所以需要尽可能多的接受外来的任务,以赚取报酬,重建村庄,假设你现在是木叶的一名高级忍者,有一大堆的任务等着你来做,但毕竟个人时间有限,所 ...
- 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 ...
- Gora官方范例 分类: C_OHTERS 2015-01-29 16:14 632人阅读 评论(0) 收藏
参考官方文档:http://gora.apache.org/current/tutorial.html 项目代码见:https://code.csdn.net/jediael_lu/mygoradem ...
随机推荐
- Social media users of the world unite!
Social media users of the world unite!全世界社交媒体用户联合起来!If Plato were alive today, he might well regard ...
- ASP.Net 下载大文件的实现
当我们的网站需要支持下载大文件时,如果不做控制可能会导致用户在访问下载页面时发生无响应,使得浏览器崩溃.可以参考如下代码来避免这个问题. 关于此代码的几点说明: 1. 将数据分成较小的部分,然后将其移 ...
- httpclient4例子
参考:http://hc.apache.org/httpclient-3.x/tutorial.html import org.apache.http.HttpEntity; import org.a ...
- poj1611(并查集简单应用)
题目链接:http://poj.org/problem?id=1611 思路: 显然是一个并查集的题,很简单,只要将一个group中的学生并在一起,最后遍历1到n-1,看有多少学生的祖先与0的祖先相等 ...
- Top K算法
应用场景: 搜索引擎会通过日志文件把用户每次检索使用的所有检索串都记录下来,每个查询串的长度为1-255字节. 假设目前有一千万个记录(这些查询串的重复度比较高,虽然总数是1千万,但如果 ...
- ImageView小技巧
ImageView截取图片的方式 centerCrop:以中心点为基准 将图片的最短边与ImageView宽度匹配 其他部分裁掉centerInside: 以中心点为基准 将图片最长边 缩进控件去
- php 使用PHPExcel 导出数据为Excel
<?php require_once 'PHPExcel/Classes/PHPExcel.php'; /** * 导出数据为Excel * @param array $fieldArr 标题数 ...
- Spring框架的JDBC模板技术概述
1. Spring框架中提供了很多持久层的模板类来简化编程,使用模板类编写程序会变的简单 2. 提供了JDBC模板,Spring框架提供的 * JdbcTemplate类 3. Spring框架可以整 ...
- oracle pl sql import export
http://blog.163.com/magicc_love/blog/static/185853662201281013345829/
- sqlserver数据库维护常用sql
1.说明:创建数据库 CREATE DATABASE database-name 2.说明:删除数据库 drop database dbname 3.说明:备份sql server --- 创建 备份 ...