zoukankan      html  css  js  c++  java
  • oj.zstu 4421交税(合数分解成素数)

    题目

    题意:T组,每一组输入一个数X,  求X最少能分成几个素数的和,输出。

    思路: 对于一个大于2的偶数,由哥德巴赫猜想,一定能分成2个素数。

                对于一个奇数来说,一定能分成2个或者3个素数之和。如果奇数 x 能被分成2个素数的和,那么一定是2和 x-2(因为奇数被分成两个数,这两个数一定是一个奇数和一个偶数,偶数只有2是素数);  如果不能分成2个素数的和, 那么只能被分成3个素数。

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cctype>
     4 #include<algorithm>
     5 #include<cstring>
     6 #include<cmath>
     7 #include<set>
     8 #include<vector>
     9 #include<stack>
    10 #include<queue>
    11 #include<map>
    12 using namespace std;
    13 #define ll long long
    14 #define mem(a,x) memset(a,x,sizeof(a));
    15 const ll mod=10000000007;
    16 const int INF=0x3f3f3f3f;
    17 const int N=1e5+5;
    18    
    19  
    20 int is_prime(int a)
    21 {
    22     for(int i=2;1*i*i<=a;i++)
    23     {
    24         if(a%i==0)
    25             return 0;
    26     }
    27     return 1;
    28 }
    29  
    30 int main()
    31 {
    32     int T;
    33     cin>>T;
    34     int x;
    35     while(T--)
    36     {
    37         cin>>x;
    38         if(x==1||x==2||x==3|| is_prime(x))
    39             cout<<1<<endl;
    40         else if(x%2==0||is_prime(x-2))
    41             cout<<2<<endl;
    42         else 
    43             cout<<3<<endl;
    44     }
    45      
    46    
    47 }
    View Code
  • 相关阅读:
    Unity Shader 之 uv动画
    c++源文件后缀名问题
    Unity Shader 之 透明效果
    正则表达式
    Unity Shader基础
    Unity Shader 之 渲染流水线
    2017/11/22 Leetcode 日记
    2017/11/21 Leetcode 日记
    2017/11/13 Leetcode 日记
    2017/11/20 Leetcode 日记
  • 原文地址:https://www.cnblogs.com/thunder-110/p/10027753.html
Copyright © 2011-2022 走看看