题目链接:Taxes
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 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可以拆成任意多个数,每个数都不为1,f(n)=最大的因子(除了其本身);使得拆的和最小;思路:显然拆成素数会使得解更优,相当于问最少拆成几个素数;根据歌德巴赫猜想;详见代码;

传送门:歌德巴赫猜想

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define esp 0.00000000001
const int N=1e5+10,M=1e6+10,inf=1e9;
const ll INF=1e18+10;
int prime(int n)
{if(n<=1)return 0;if(n==2)return 1;if(n%2==0)return 0;int k, upperBound=n/2;for(k=3; k<=upperBound; k+=2){upperBound=n/k;if(n%k==0)return 0;}return 1;
}
int main()
{int x;scanf("%d",&x);if(prime(x))return puts("1");if(x%2==0)return puts("2");if(prime(x-2))return puts("2");puts("3");return 0;
}

转载于:https://www.cnblogs.com/jhz033/p/6110097.html

Codeforces Round #382 (Div. 2) D. Taxes 歌德巴赫猜想相关推荐

  1. 2017年浙工大迎新赛热身赛 J Forever97与寄信 【数论/素数/Codeforces Round #382 (Div. 2) D. Taxes】...

    时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 131072K,其他语言262144K 64bit IO Format: %lld 题目描述 Forever97与未央是一对笔友,他们经 ...

  2. Codeforces Round #382 (Div. 2)B. Urbanization 贪心

    B. Urbanization 题目链接 http://codeforces.com/contest/735/problem/B 题面 Local authorities have heard a l ...

  3. Codeforces Round #382 (Div. 2)C. Tennis Championship(贪心) D.巴赫猜想

    C: 题意:每个人输了比赛就会被淘汰,每两个人可以打比赛的要求是a赢过x场比赛b赢过y场比赛则当abs(x - y) <= 1 时他们可以进行比赛,总共n个选手,问最终的赢家可能赢过的场次的最大 ...

  4. Codeforces Round #506 (Div. 3)

    Codeforces Round #506 (Div. 3) 实习期间事不多,对div3 面向题解和数据编程了一波 A. Many Equal Substrings 题目链接 A题就是找后缀和前缀重合 ...

  5. Codeforces Round #563 (Div. 2)/CF1174

    Codeforces Round #563 (Div. 2)/CF1174 CF1174A Ehab Fails to Be Thanos 其实就是要\(\sum\limits_{i=1}^n a_i ...

  6. 构造 Codeforces Round #302 (Div. 2) B Sea and Islands

    题目传送门 1 /* 2 题意:在n^n的海洋里是否有k块陆地 3 构造算法:按奇偶性来判断,k小于等于所有点数的一半,交叉输出L/S 4 输出完k个L后,之后全部输出S:) 5 5 10 的例子可以 ...

  7. Codeforces Round #696 (Div. 2) (A ~ E)超高质量题解(每日训练 Day.16 )

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #696 (Div. 2) (A ~ E)超高质量题解 比赛链接:h ...

  8. Codeforces Round #712 Div.2(A ~ F) 超高质量题解(每日训练 Day.15 )

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #712 Div.2(A ~ F) 题解 比赛链接:https:// ...

  9. Codeforces Round #701 (Div. 2) A ~ F ,6题全,超高质量良心题解【每日亿题】2021/2/13

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 目录 A - Add and Divide B - Replace and Keep Sorted C ...

最新文章

  1. 事件标志组的删除与状态查询
  2. 算法试题 - 找出字符流中第一个不重复的元素
  3. 【蓝桥杯官网试题 - 历届试题】格子刷油漆(dp)
  4. BugkuCTF-Reverse题signin
  5. 函数或变量 rtenslearn_c 无法识别_深度学习的数学-卷积神经网络的结构和变量关系...
  6. 解决低版本IE关于html5新特性的兼容性问题html5shiv.js和Respond.js,以及excanvas.js解决低版本IE不支持canvas的问题...
  7. java类加载器ClassLoader浅析
  8. 在C#中如何读取枚举值的描述属性
  9. Excel导入导出之easypoi用法
  10. html中选择器是什么意思,css选择器是什么意思?
  11. MySQL报错`ERROR: No query specified`
  12. 奶牛戴上VR眼镜“看片”,开心了可以多产奶:俄罗斯官方做了实验,拯救奶牛的冬季忧郁...
  13. [文献翻译自用]运用本地差分隐私的基于物品的协同过滤
  14. 面板数据熵值法计算综合指数Stata代码(附样本数据和结果)
  15. HoloLens2开发常见问题汇总
  16. fastlane 上传到蒲公英和Fir 配置
  17. 论文计算机本科字数,211本科毕业论文多少字?毕业论文多少字数要求
  18. 操作系统基础教程——第六章课后答案
  19. 雷锋网的那些段段(一)。
  20. 软件企业双软认证的条件和好处是什么

热门文章

  1. Java终止线程的三种方式
  2. android window设置动画,android - 具有动画的Windowmanager
  3. 汇编语言定时器转化为c语言,不用定时器和汇编语言,只用C语言实现精确无误的延时...
  4. rsync+inotify 文件同步
  5. Java 的数据类型示意图
  6. display: flex的兼容性写法
  7. 你能理解、不能理解和不需要理解的量子计算
  8. 字符串 - KMP模式匹配
  9. SVN版控系统的安装和使用
  10. .NET PPT控件 Spire.Presentation for .NET V2.8发布 | 附下载