zoukankan      html  css  js  c++  java
  • HDU2098 分拆素数和

    Problem Description
    把一个偶数拆成两个不同素数的和,有几种拆法呢?
     
    Input
    输入包含一些正的偶数,其值不会超过10000,个数不会超过500,若遇0,则结束。
     
    Output
    对应每个偶数,输出其拆成不同素数的个数,每个结果占一行。
     
    Sample Input
    30
    26
    0
     
    Sample Output
    3
    2
     
    解题思路:先欧拉筛数然后在进行试探分析是否可以两个素数的和为这个偶数。
    import java.util.Scanner;
    
    public class Test {
        public static void main(String[] args){
            Scanner input = new Scanner(System.in);
            
            int count =0;
            int num = 100000;
            boolean[] bl = new boolean[100000000];
            int[]  primeList = new int[num];
            for(int i =2;i < num;i++){
                if(!bl[i]){
                    primeList[count++] = i;
                }
                for(int j =0;j < count;j++){
                    if(i*primeList[j] > num){
                        break;
                    }
                    bl[i*primeList[j]] = true;
                    if(i%primeList[j]==0){
                        break;
                    }
                }
            }
            
            for(;;){
                int sum = input.nextInt();
                if(sum ==0){
                    break;
                }
                int count1 =0;
                for(int i =2;i < sum/2;i++){
                    if(!bl[i]&&!bl[sum-i]){
                        if(i!=sum-i)
                        count1++;
                        System.out.println(i+" " +(sum-i));
                    }
                    
                }
                System.out.println(count1);
            }
            
        }
    }
  • 相关阅读:
    GlowFilter发光效果
    投影滤镜的使用
    flash怎样删除库中没用的元件
    script中用php
    jQuery animate实现slideUp slideDown 的反向
    CSS !important 用法
    放新浪微博的箭头css写法
    json 取数据
    css hack 大全
    bubble 界面代码
  • 原文地址:https://www.cnblogs.com/ke-T3022/p/8385311.html
Copyright © 2011-2022 走看看