• 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 = 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.

    读题易想到所有素数都只算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
  • 相关阅读:
    Eclipse 导入外部项目无法识别为web项目并且无法在部署到tomcat下
    Android开发-API指南-<activity-alias>[原创译文]
    深入WeakHashMap
    寻找第K大数的方法总结
    overridePendingTransition的简介
    Oracle执行CreateTableAs报ORA-600错误
    HahaMil数据库(数据库操作组件)
    List(支持按笔画排序的List类)
    关于我的网站(八零家园三周年)
    走出象牙塔之Final(2014.07.07)
  • 原文地址:https://www.cnblogs.com/ToTOrz/p/7294718.html
Copyright © 2020-2023  润新知