跳过正文
  1. Posts/

codeforces #382 div2 D. Taxes(哥德巴赫猜想)

题目链接

题意:一个人有n元前,他要交的税是n的最大因子(除n外),现在这个投机倒把者想把前分成k部分(k为大于等于1的任意值)每部分不能为1,分别交税,问最少交多少税。

思路:要说因子小。。很容易想到素数。。。然后就很容易想到了维基百科_哥德巴赫猜想

内容是:任何一个大于2的偶数可以写成两个素数的和。

(虽然是一个猜想没有被证明。。。但是1E9这种级别正确性还是很显然的2333

那么任何大于2的偶数,答案就是2

奇数可以分成一个3和一个偶数,答案为3.

不过这可能还不够优,这也是这道题的两个trick所在:

如果该数本身为素数,那么不用分(k取1),答案为1

如果该数减去2为素数,那么答案为2.

 1/* ***********************************************
 2Author :111qqz
 3Created Time :2016年11月29日 星期二 11时36分56秒
 4File Name :code/cf/#382/D.cpp
 5************************************************ */
 6
 7#include <cstdio>
 8#include <cstring>
 9#include <iostream>
10#include <algorithm>
11#include <vector>
12#include <queue>
13#include <set>
14#include <map>
15#include <string>
16#include <cmath>
17#include <cstdlib>
18#include <ctime>
19#define fst first
20#define sec second
21#define lson l,m,rt<<1
22#define rson m+1,r,rt<<1|1
23#define ms(a,x) memset(a,x,sizeof(a))
24typedef long long LL;
25#define pi pair < int ,int >
26#define MP make_pair
27
28using namespace std;
29const double eps = 1E-8;
30const int dx4[4]={1,0,0,-1};
31const int dy4[4]={0,-1,1,0};
32const int inf = 0x3f3f3f3f;
33LL n;
34bool prime( LL x)
35{
36    for ( LL i = 2 ; i*i <= x ; i++)
37    {
38	if (x%i==0) return false;
39    }
40    return true;
41}
42LL solve( LL x)
43{
44    if (prime(x)) return 1;
45    if (x%2==0) return 2;
46    if (x%2==1)
47    {
48	if (prime(x-2)) return 2;
49	else return 3;
50    }
51}
52int main()
53{
54	#ifndef  ONLINE_JUDGE
55	freopen("code/in.txt","r",stdin);
56  #endif
57	cin>>n;
58	LL ans = solve(n);
59	cout<<ans<<endl;
60
61  #ifndef ONLINE_JUDGE
62  fclose(stdin);
63  #endif
64    return 0;
65}

相关文章

cf 611 B ||codeforces goodbye 2015 B. New Year and Old Property (数学或者数位dp)

http://codeforces.com/contest/611/problem/B 题意:问a到b(1E18),二进制表示中只有一个0的数有多少个。 思路:这么大的数。。。不是有循环节就是math problems. UD:20160318讲道理还有可能是数位dp好不好。。。 我们发现可以很容易得算出1到x的二进制表示中只有一个0 的数有多少个。

hdu 2138 How many prime numbers

ACM STEPS里的…这题前面一道是求LCM….结果接下来就是这么一道。。。 朴素会超….筛法会爆….题目顺序真是按照难度来的? 于是想到 Miller-Rabin素数测试……. 这个方法是基于费马小定理 我的理解就是… 如果我要判断n是否为素数 只要取k个数 如果满足 a^(n-1)mod n =1 那么n就很可能为素数。 证明什么的…暂时还是算了吧…论文里貌似扯了一大堆 第一次用,竟然真的A了。。。。 感觉更好的办法也许是先打一个比较小的素数表,然后每次random选取若干个进行判断…那样应该更可靠些? 本来想WA掉之后再改的。。。没想到这么写就A掉了。。。。杭电数据略水?

codeforces #382 div2 C. Tennis Championship(打表找规律)

·1 分钟
题目链接 题意:n个人进行淘汰赛制的比赛,输的人直接被淘汰,不进行下一轮,现在要求两个人可以比赛当且仅当两个人的胜场数相差小于等于1,现在问赢得最多场的那个人,最多可能赢多少场。