题解 | #牛牛的素数和#

牛牛的素数和

http://www.nowcoder.com/practice/d748d79f68ab443482c5547d93824f50

import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int first = scanner.nextInt();
        int second = scanner.nextInt();
        int sum = 0;
        for(int index = first; index <= second; index++){
            if(check(index)){
                sum += index;
            }
        }
        System.out.print(sum);
    }
    
    private static boolean check(int num){
        if (num < 2) return false;
        for (int index = 2; index <= num / index; index++ )
        {
            if (num % index == 0) {
                return false;
            }
        }
        return true;
    }
}

全部评论

相关推荐

点赞 评论 收藏
分享
一表renzha:不是你说是南通我都没往那方面想,人家真是想表达那个意思吗?
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-08 17:10
点赞 评论 收藏
分享
评论
2
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务