Codeforces 735D. Taxes
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
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 n
Ostap Bender wonders, how many money Funt has to pay (i.e. minimal) if he chooses and optimal way to split n in parts.
InputThe first line of the input contains a single integer n (2?≤?n?≤?2·109) — the total year income of mr. Funt.
OutputPrint one integer — minimum possible number of burles that mr. Funt has to pay as a tax.
讀題易想到所有素數都只算1的稅,所以聯想到分解成素數(本身素數那就是1)。然後根據哥德巴赫猜想,所有偶數可以分解為兩個素數的和,所以除了2以外的所有偶數答案都是2,而對於非素數奇數就是看他能不能分解2+素數的形式,否則就是3
#include <iostream> #include <iomanip> #include <cstring> #include <cstdio> #include <cmath> #include <algorithm> 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
Codeforces 735D. Taxes