Codeforces Round #382 (Div. 1) B. Taxes
来源:互联网 发布:天刀男性捏脸数据 编辑:程序博客网 时间:2024/05/17 11:59
B. Taxes
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard 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除本身外的最大因数,可以将收入n分成k份,每份不能为1,分成k份后取每份的因数加和作为税额。
题解:根据素数的因子是除本身外就是1,因此素数收入的税额是最小的,根据哥德巴赫猜想,任何偶数都可拆分成两个质数,因此偶数收入的税额必定是2,素数税额必定是1,奇数分为3中情况,一种作为素数税额为1,一种作为奇数,但减2后得到一个素数,因此可以看成是两个素数之和,税额也为2。第三种是奇数减2之后仍是一个普通奇数,但再减2之后可以得到一个素数,因此是2+2+素数,三个素数之和税额为3。
#include<stdio.h>///判断素数的方法,就是从2一直到sqrt(n)判断取摸是否有为0#include<string.h>///可以不用素数筛,单个数判断素数#include<math.h>bool judge(long long n)///分3种情况,根据哥德巴赫猜想,一个不为2的偶数必能拆成两个素数之和,所以偶数n纳税都是2{ int x=n,i; for(i=2; i<=sqrt(n); i++)///奇数分两种情况,一种就是素数,另一种是,奇数-2后是一个素数,此时可分成2+一个素数,纳税为2 { while(x%i==0) { return false;///第三种情况,奇数-2不为素数,此时奇数被分为3个素数相加,纳税为3 } } return true;}int main()///题目要纳的税是收入n的最大因子(除去n),并且可以把n分成不为1的很多份{///求纳税最小值 int i,n; while(scanf("%d",&n)!=EOF)///也就是当分成很多个素数时,纳税都是1 { if(judge(n))///若是质数。最大因子为1 { printf("1\n"); continue; } if(n%2==0)///若是偶数,可分解为两个质数之和 printf("2\n"); else///非素数的奇数,有两种情况 { if(judge(n-2)) printf("2\n"); else printf("3\n"); } }}///以下是分解质因数的方法//void zhiyinshu(int n)//{// int x=n,i;// printf("%d=",n);// for(i=2;i<=sqrt(n);i++)// {// while(x%i==0)// {// if(x==i)// break;// x/=i;// printf("%d*",i);// }// }// printf("%d\n",x);//}
- Codeforces Round #382 (Div. 1) B. Taxes
- Codeforces Round #382 (Div. 1) B. Taxes
- Codeforces Round #382 (Div. 1) 736B Taxes
- Codeforces Round #382 (Div. 2) D. Taxes
- Codeforces Round #382 (Div. 2) D. Taxes
- Codeforces Round #382 (Div. 2) -- D. Taxes
- Codeforces Round #382 (Div. 2) D. Taxes 数论、哥德巴赫猜想
- Codeforces Round #382 (Div. 2)D. Taxes(数论知识)
- Codeforces Round #382 (Div. 2) 735D - Taxes
- Codeforces Round #382 (Div. 2)-D. Taxes(歌德巴赫猜想)
- Codeforces Round #382 (Div. 2) D Taxes(数论)
- Codeforces Round #382 (Div. 2)D. Taxes(哥德巴赫猜想)
- Codeforces Round #382 (Div. 2) D. Taxes (哥德巴赫猜想)
- Codeforces Round #382 (Div. 2)A到D题 A. Ostap and //B. Urbanization//C. Tennis Championship//D. Taxes
- 【21.21%】【codeforces round 382D】Taxes
- Codeforces Round #382 (Div. 2) D. Taxes(分拆素数和)
- Codeforces Round #382 (Div. 2)-735D. Taxes(哥德巴赫猜想?!)
- Codeforces Round #382 (Div. 2) -- D. Taxes (数学 -- 哥德巴赫猜想, 唯一分解定理)
- jvm类加载机制
- POJ 2796 (前缀数组或者单调栈)
- 104. Maximum Depth of Binary Tree
- 在list页面双击显示重叠明细
- 大文件计算MD5值 ——Python
- Codeforces Round #382 (Div. 1) B. Taxes
- time-lock and phase-lock signal
- leetocde 374. Guess Number Higher or Lower
- okhttp的坑坑坑 unexpected end of stream on Connection
- 计算机图形学笔记---Cg语言(一)
- 学习下ACM的题目
- 几种常见的Dialog
- Microsoft c++ Speech 识别接口快速入门
- [LeetCode] Rotate List