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 ...
随机推荐
- hadoop 集群安装配置 【转】
http://www.cnblogs.com/ejiyuan/p/5557061.html 注意:要把master 上所有的配置文件(主要是配置的那四个 xxxx-site.xml 和 xxx-env ...
- jquery读取本地文件,Windows上报错。XMLHttpRequest cannot load xxx. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.k.cors.a.c
问题: 测试报告,使用本地的json.txt文件,结果文件读取失败,报错如下: XMLHttpRequest cannot load xxx. Cross origin requests are on ...
- SVN服务器端的安装和配置
第2章 SVN 的下载与安装 服务器端的安装和配置 所有的开发人员用自己的账号登录进来就可以拥有对仓库里面的所有文件的读和写的权限 创建用户
- hbase概念
1. 概述(扯淡~) HBase是一帮家伙看了Google发布的一片名为“BigTable”的论文以后,犹如醍醐灌顶,进而“山寨”出来的一套系统. 由此可见: 1. 几乎所有的HBase中的理念,都可 ...
- php的无刷新实现方法
方法一: 我们通过http的204状态码,页面不跳转. 1.html代码如下: <!DOCTYPE HTML> <html lang="zh-CN"> &l ...
- linux-centos6-rabbitmq安装及配置
服务器版本centos6.8 一.先安装Erlang 具体安装哪个版本可以对照 http://www.rabbitmq.com/which-erlang.html 如下图: 准备安装RabbitMQ3 ...
- yaf框架安装配置
YAF中文文档:http://www.laruence.com/manual/index.html 1 YAF框架是用C开发的,属于PHP的扩展框架: 2 YAF的性能相对于源生PHP,性能只降低不到 ...
- C语言字符串操作函数实现
1.字符串反转 – strRev void strRev(char *str) { assert(NULL != str); int length=strlen(str); ; while(end ...
- Linux系统 SecureCRT SecureFX 注册破解方法
1.创建脚本文件crack-binary.sh,内容如下: #!/bin/sh cd $1 cat SecureCRT | od -A n -v -t x1 | tr -d ' \n ...
- 调用数据库--stone
from Mysql_operate_class import mysql def saveMysqlData(sql, dbname="algorithm"): pym = my ...