hdu_2012 素数判定
来源:互联网 发布:美视软件 编辑:程序博客网 时间:2024/06/04 18:14
import java.util.Scanner;/** * Created by feyman1120 on 2017/11/24. */public class Main { /*如果一个数不能被2到它的平方根整除,则说明为一个素数*/ public static boolean isPrime(int x){ int y = (int)Math.sqrt(x); for (int i = 2; i <= y; ++i){ if (x % i == 0){ return false; } } return true; } public static void main(String[] args) { Scanner scan = new Scanner(System.in); while (scan.hasNext()) { int st = scan.nextInt(); int ed = scan.nextInt(); if (0 == st + ed){ break; } /*交换两个数*/ if (st > ed) { st = st ^ ed; ed = st ^ ed; st = st ^ ed; } boolean flg = false; for (int i = st; i <= ed; ++i){ int y = i * i + i + 41; if (!isPrime(y)){ flg = true; break; } } if (flg){ System.out.println("Sorry"); } else { System.out.println("OK"); } } }}
阅读全文
0 0
- hdu_2012素数判定
- hdu_2012 素数判定
- 素数判定
- 素数判定
- 素数判定
- 素数判定
- 素数判定
- 素数判定
- 素数判定
- 素数判定
- 素数判定
- 素数判定
- 素数判定
- 素数判定
- 素数判定
- 素数判定
- 素数判定!
- 素数判定
- Java基本类型的包装器类型的缓存策略及双等号使用问题
- Redis可视化工具无法安装解决方案
- poj Til the Cows Come Home (Dijkstra最短路~)
- MyBatis返回Map键值对数据
- Algorithms For Dummies.pdf 英文原版 免费下载
- hdu_2012 素数判定
- Apple Tree(树形DP)
- 在TensorFlow使用RNN(读书笔记)
- Spring,Mybatis,Hibernate,Struts2 -- 4大框架复习
- ES6新的数据类型set
- Based on MT5 Gateway API Quotes and Trading Liquidity
- Pro C 7, 8th Edition.pdf 英文原版 免费下载
- 悼念512汶川大地震遇难同胞——珍惜现在,感恩生活
- DispatcherServlet