博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces 735D. Taxes
阅读量:4919 次
发布时间:2019-06-11

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

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.

 

读题易想到所有素数都只算1的税,所以联想到分解成素数(本身素数那就是1)。然后根据哥德巴赫猜想,所有偶数可以分解为两个素数的和,所以除了2以外的所有偶数答案都是2,而对于非素数奇数就是看他能不能分解2+素数的形式,否则就是3

#include 
#include
#include
#include
#include
#include
using namespace std;typedef long long LL;LL n;LL res = 0;bool isprime(LL n){ if (n == 2){ return true; } for (int i=2;i<=sqrt(n);i++){ if (n % i == 0){ return false; } } return true;}int main(){ // freopen("test.in","r",stdin); cin >> n; if (isprime(n)){ cout << 1; return 0; } if (n % 2 == 0){ cout << 2; } else { if (isprime(n-2)){ cout << 2; } else cout << 3; } return 0;}
View Code

 

转载于:https://www.cnblogs.com/ToTOrz/p/7294718.html

你可能感兴趣的文章
杭电2061
查看>>
硬盘的工作原理
查看>>
开发日志
查看>>
使用 Intellij Idea 导出JavaDoc
查看>>
js -- 写个闭包
查看>>
属性动画
查看>>
html5中<body>标签支持的事件
查看>>
F. 约束
查看>>
安装 jdk
查看>>
对康拓展开式和逆康托展开式的认识
查看>>
第二次作业(homework-02)成绩公布
查看>>
KVM&amp;Libvirt基本概念及开发杂谈
查看>>
flv视频格式详细解析
查看>>
Python装饰器
查看>>
美剧推荐之《越狱》
查看>>
网络相关知识
查看>>
Chapter 1 Securing Your Server and Network(5):使用SSL加密会话
查看>>
19、路由和拓扑图和lan
查看>>
编写高性能 Web 应用程序的 10 个技巧
查看>>
a 锚点跳转滑动效果
查看>>