D. Taxes

题目链接

http://codeforces.com/contest/735/problem/D

题面

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.

输入

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

题面

现在给你一个数n,他的代价就是他除开本身的最大因子。

现在你可以把n拆成几个数相加,这样代价就是那几个数的代价的和。

问你最小的代价是啥。

题解

拆成素数的话,答案就是1

根据哥德巴赫猜想,大于2的偶数都可以变成两个素数的和。

大于5d奇数,都可以拆成三个素数的和。

代码

#include<bits/stdc++.h>
using namespace std; long long n;
bool check(int x){
for(int i=2;i*i<=x;i++){
if(x%i==0)return false;
}
return true;
}
int main()
{
scanf("%lld",&n);
if(n>2&&n%2==0){
printf("2\n");
}else if(n==2){
printf("1\n");
}else{
if(check(n))cout<<"1"<<endl;
else if(check(n-2))cout<<"2"<<endl;
else cout<<"3"<<endl;
}
}

Codeforces Round #382 (Div. 2) D. Taxes 哥德巴赫猜想的更多相关文章

  1. Codeforces Round #382 (Div. 2) D. Taxes 歌德巴赫猜想

    题目链接:Taxes D. Taxes time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

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

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

  3. codeforces736b Taxes (Codeforces Round #382 (Div. 1))

    题意:纳税额为金额的最大因数(除了本身).为了逃税将金额n分为n1+n2+.......问怎样分纳税最少. 哥德巴赫猜想: 任一大于2的偶数都可写成两个质数之和. 质数情况: 任何大于5的奇数都是三个 ...

  4. Codeforces Round #382 Div. 2【数论】

    C. Tennis Championship(递推,斐波那契) 题意:n个人比赛,淘汰制,要求进行比赛双方的胜场数之差小于等于1.问冠军最多能打多少场比赛.题解:因为n太大,感觉是个构造.写写小数据, ...

  5. Codeforces Round #382 (Div. 2) 继续python作死 含树形DP

    A - Ostap and Grasshopper zz题能不能跳到  每次只能跳K步 不能跳到# 问能不能T-G  随便跳跳就可以了  第一次居然跳越界0.0  傻子哦  WA1 n,k = map ...

  6. Codeforces Round #382 (Div. 2) (模拟|数学)

    题目链接: A:Ostap and Grasshopper B:Urbanization C:Tennis Championship D:Taxes 分析:这场第一二题模拟,三四题数学题 A. 直接模 ...

  7. Codeforces Round #382(div 2)

    A.= = B. 题意:给出n个数和n1和n2,从n个数中分别选出n1,n2个数来,得到n1个数和n2个数的平均值,求这两个平均值的最大和 分析:排个序从后面抽,注意先从末尾抽个数小的,再抽个数大的 ...

  8. Codeforces Round #382 (Div. 2) 解题报告

    CF一如既往在深夜举行,我也一如既往在周三上午的C++课上进行了virtual participation.这次div2的题目除了E题都水的一塌糊涂,参赛时的E题最后也没有几个参赛者AC,排名又成为了 ...

  9. Codeforces Round #382 (Div. 2)C. Tennis Championship 动态规划

    C. Tennis Championship 题目链接 http://codeforces.com/contest/735/problem/C 题面 Famous Brazil city Rio de ...

随机推荐

  1. Android照片墙应用实现,再多的图片也不怕崩溃

    本文首发于CSDN博客,转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/9526203 照片墙这种功能现在应该算是挺常见了,在很多应用 ...

  2. select 练习2

    group by :select 分组字段,聚合函数 from 表名 where  条件 group by 分组字段 having 过滤条件 select cno,avg(degree) from s ...

  3. Ubuntu下制作ISO文件

    利用Ubuntu自带的命令mkisofs就可以制作iso文件,具体方法如下: 1.   如果你是直接从cd压制iso文件的,执行 sudo umount /dev/cdromdd if=/dev/cd ...

  4. 【10_169】Majority Element

    今天遇到的题都挺难的,不容易有会做的. 下面是代码,等明天看看Discuss里面有没有简单的方法~ Majority Element My Submissions Question Total Acc ...

  5. codeforces 425E

    题意:对于[l1, r1], [l2, r2]...[lm, rm]线段组成的一个集合S,我们定义f(S)为最大的不相交(没有任何公共点)线段数,现在给定n及k,n表示线段范围,即任何[li, ri] ...

  6. [Windows-Linux]Windows and Linux 共享文件

    在 windows 上共享一个文件夹 共享操作很简单就不多熬述,不过要注意权限分配问题.我们假定共享了 E:\Develop\Share 这个目录. 我们假设主机局域网的 IP 为 192.168.0 ...

  7. 15 个很棒的 Bootstrap UI 界面编辑器

    Bootstrap Magic BootSwatchr Bootstrap Live Editor Fancy Boot Style Bootstrap Lavish Bootstrap ThemeR ...

  8. linux下解决端口被占用问题

    查找被占用的端口: netstat -tln netstat -tln | grep 8080   查看端口属于哪个程序 lsof -i :8080   杀掉占用端口的进程: kill -9 进程ID ...

  9. 学一点Git--20分钟git快速上手

    (图片已修复)在Git如日中天的今天,不懂git都不好意思跟人说自己是程序猿.你是不是早就跃跃欲试了,只是苦于没有借口(契机). 好吧,机会就在今天. 给我20分钟,是的,只要20分钟, 让你快速用上 ...

  10. PHP 开发社区微信服务号实战图解

    本博文就月初刚上线的微信服务号,图文进行总结分享给大家. 去年年底,我所在的团队讨论要开发微信号,话题由此拉开: 原来有一个3年前注册的微信号,但是后台操作无法从“订阅号”变更为“服务号”,随即找腾讯 ...