当前位置:网站首页>Xiao Lan does experiments (count the number of primes)
Xiao Lan does experiments (count the number of primes)
2022-06-21 15:37:00 【iFulling】
【 Problem description 】
Xiao Lan likes scientific research very much , He recently made an experiment and got a batch of experimental data , That's twomillion positive integers . If as expected , All the experimental data x All should be satisfied 1 0 7 ≤ x ≤ 1 0 8 10^7 ≤ x ≤ 10^8 107≤x≤108. But there will be some errors when doing experiments , It will lead to some unexpected data , This error data y The range is 1 0 3 ≤ y ≤ 1 0 12 10^3 ≤ y ≤ 10^{12} 103≤y≤1012 . Because Xiao Lan is very reliable in doing experiments , So of all his experimental data 99.99% All the above are in line with expectations . All the experimental data of Xiaolan are in primes.txt in , Now he wants to count how many of the twomillion positive integers are prime numbers , Can you tell him ?
【 material 】
Baidu network disk link : primes.txt
Extraction code : imfa
【 Problem solving 】
The theorem is used here : If a number is a composite number , Then its minimum prime factor must be less than or equal to its square root .
【 Code 】
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
public class B {
public static void main(String[] args) throws IOException {
int count = 0;
BufferedReader reader = new BufferedReader(new FileReader("src/primes.txt"));
String line = null;
while ((line = reader.readLine()) != null) {
long num = Long.parseLong(line);
if (check(num)) {
System.out.println(num);
count++;
}
}
reader.close();
System.out.println(count);
}
public static boolean check(double nums) {
/* * Judge whether it is a prime number * */
boolean ret = true;
for (int i = 2; i <= (int) (Math.pow(nums, 0.5) + 1); i++) {
if (nums % i == 0) {
ret = false;
break;
}
}
return ret;
}
}
边栏推荐
- Several common implementation methods of mock interface test
- Someone is storing credit card data - how do they do it- Somebody is storing credit card data - how are they doing it?
- Redis5.0 installation and production startup steps
- PLSQL learning log
- Based on Transformer's artificial neural network, the image of organic structure is transformed into molecular structure
- Retrieve the compressed package password
- Telnet batch test (II): key codes for the implementation of Telnet batch test script
- Counter attack of flour dregs: MySQL 66 questions, 20000 words + 50 pictures!
- Representation learning of resting fMRI data based on variational self encoder
- 微服务架构带来的分布式单体
猜你喜欢

Several common implementation methods of mock interface test

Gold, silver and four interviews are necessary. The "brand new" assault on the real topic collection has stabilized Alibaba Tencent bytes

Select everything between matching brackets in vs Code - select everything between matching brackets in vs Code

Defcampctf2122 Forensics

ABP Framework 5.3.0 版本新增功能和变更说明

Operator Tour (I)

After the uproar, is the yuan universe "cool"?

Phantom star VR product details 34: Happy pitching

For the first time in China, Tsinghua and other teams won the wsdm2022 only best paper award, and Hong Kong Chinese won the "time test Award"

GO语言-结构体
随机推荐
Nodejs process has too many open files
Why do you want to be naked with a router
Analysis report on competition trend and development scale of China's heavy packaging industry 2022-2028 Edition
Phy336 Computational Physics
Retrieve the compressed package password
階乘求和
Basic concepts of database
Phantom star VR product details 32: Infinite War
Stm32l431 immediate sleep mode (code + explanation)
Complete and detailed installation steps for kubeneter version 1.7
Daily practice (23): the first character that appears only once
Leetcode: number of good subsets (backtracking + state compression +dfs + pruning)
Crontab pit stepping record: manual script execution is normal, but crontab timed script execution is abnormal
shell使用数组
Kitchen appliance giant employee data was leaked during the attack, and Iran's national radio was attacked by malware | February 22 global network security hotspot
C language pointer
Perfect partner of ebpf: cilium connected to cloud native network
Counter: a simple and free network traffic analysis tool
GO语言-type关键字
MySQL transaction