Codeforces Round #382 (Div. 2) D. 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
Copy
4
output
Copy
2
input
Copy
27
output
Copy
3
哥德巴赫猜想 (一)任意大于2的偶数n都可以表示成两个质数的和 (二)任意大于5的整数n都可以表示成三个质数的和 首先n=2或3或者是质数,答案是1,对于大于2的数,如果是偶数,那么答案是2最优(用哥猜结论)
如果是奇数但不是质数,最差答案是3,当且仅当n-2是质数的时候是2~
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rg register ll
#define inf 2147483647
#define lb(x) (x&(-x))
ll sz[200005],n;
template <typename T> inline void read(T& x)
{
x=0;char ch=getchar();ll f=1;
while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
while(isdigit(ch)){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}x*=f;
}
inline ll query(ll x){ll res=0;while(x){res+=sz[x];x-=lb(x);}return res;}
inline void add(ll x,ll val){while(x<=n){sz[x]+=val;x+=lb(x);}}//第x个加上val
inline bool f(ll x)
{
if(x<=3)return 1;
for(rg i=2;i*i<=x;i++)
{
if(x%i==0)return 0;
}
return 1;
}
inline ll cnt(ll x)
{
ll max=-1;
for(rg i=1;i*i<=x;i++)
{
if(x%i==0)max=i;
}
return max;
}
int main()
{
cin>>n;
ll ans=0;
if(n<=3||f(n))cout<<1<<endl;
else
{
if(n%2==0)cout<<2<<endl;
else
{
for(rg j=n-2;;j--)
{
if(f(j))
{
cout<<min(1+cnt(n-j),3ll)<<endl;
break;
}
}
}
}
return 0;
}
- JavaScript操作Cookie
- Windows下Go环境安装
- Angular定义服务-Learn By Doing
- JS魔法堂:不完全国际化&本地化手册 之 理論篇
- mysql替换某个字段中的某个字符
- Angular企业级开发(1)-AngularJS简介
- PHP在Apache下500错误
- mysql 学习笔记
- MongoDB学习系列(2)--使用PHP访问MongoDB
- (cljs/run-at (JSVM. :browser) "命名空间就这么简单")
- Angular企业级开发(10)-Smart Table插件开发
- 安装Ubuntu时分区选择
- linux系统下安装两个或多个tomcat
- JS魔法堂:不完全国际化&本地化手册 之 实战篇
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法