当前位置:网站首页>Interesting prime number problem hdu5750
Interesting prime number problem hdu5750
2022-04-23 05:08:00 【FOWng_ lp】
A positive proper divisor is a positive divisor of a number n, excluding n itself. For example, 1, 2, and 3 are positive proper divisors of 6, but 6 itself is not.
Peter has two positive integers n and d. He would like to know the number of integers below n whose maximum positive proper divisor is d.
Input
There are multiple test cases. The first line of input contains an integer T (1≤T≤106), indicating the number of test cases. For each test case:
The first line contains two integers n and d (2≤n,d≤109).
Output
For each test case, output an integer denoting the answer.
Sample Input
9
10 2
10 3
10 4
10 5
10 6
10 7
10 8
10 9
100 13
Sample Output
1
2
1
0
0
0
0
0
4
Worth considering ,HDU5750
Especially where notes are added !
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
bool isPrime[100000100];
int Prime[600010], cnt = 0;
void GetPrime(int n)// Sieve to n
{
memset(isPrime, 1, sizeof(isPrime));
isPrime[1] = 0;//1 Not primes
for(int i = 2; i <= n; i++)
{
if(isPrime[i])// Didn't sift out
Prime[++cnt] = i; //i Become the next prime
for(int j = 1; j <= cnt && i*Prime[j] <= n/* Don't exceed the upper limit */; j++)
{
isPrime[i*Prime[j]] = 0;
if(i % Prime[j] == 0)//i Also contains Prime[j] This factor
break; // major measure . See principle
}
}
}
int main(){
int n;
int a = 0,b,x,ans,pri=0;
GetPrime(300005);
cin >> n;
while(n--){
ans=0;
scanf("%d %d",&a,&b);
for(int i = 1;Prime[i]*b < a&&Prime[i]<=b;i++){
ans++;
if(b%Prime[i]==0)break;
// If d Is a multiple of the current prime , namely d = pri[i] * x', So when it comes to the next prime number , because d' = pri[i + 1] * x' > d,d There is no guarantee that it will be the largest , So when d When it can be divided by a prime number , It's about to exit the loop
}
printf("%d\n",ans);
}
return 0;
}
版权声明
本文为[FOWng_ lp]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220549345598.html
边栏推荐
- Servlet3 0 + event driven for high performance long polling
- Some experience in using MySQL / tidb database [slowly updating...]
- Use AES encryption - reuse the wisdom of predecessors
- Detailed explanation of concurrent topics
- What are instruction cycles, machine cycles, and clock cycles?
- Agile practice | agile indicators to improve group predictability
- 【数据库】MySQL多表查询(一)
- Download PDF from HowNet (I don't want to use CAJViewer anymore!!!)
- Kubectl command automatic replenishment
- Details related to fingerprint payment
猜你喜欢
Making message board with PHP + MySQL
AQS source code reading
Learning Android from scratch -- Introduction
MySQL -- execution process and principle of a statement
Discussion on flow restriction
深度学习笔记 —— 数据增广
Learning Android II from scratch - activity
Detailed explanation of the differences between TCP and UDP
Download PDF from HowNet (I don't want to use CAJViewer anymore!!!)
[database] MySQL multi table query (I)
随机推荐
At pgconf Asia Chinese technology forum, listen to Tencent cloud experts' in-depth understanding of database technology
MySQL -- execution process and principle of a statement
Harmonious dormitory (linear DP / interval DP)
Summary of R & D technology
Basic concepts of multithreading (concurrency and parallelism, threads and processes) and entry cases
DIY 一个 Excel 版的子网计算器
【数据库】MySQL单表查询
JS engine loop mechanism: synchronous, asynchronous, event loop
One month countdown, pgconf What are the highlights of the latest outlook of asia2021 Asian Conference?
Detailed explanation of hregionserver
Use the built-in function of win to transfer files between two computers in the same LAN (the speed is the same as that between local disks)
Innovation training (XII) reptile
Mac enters MySQL terminal command
Chapter II project scope management of information system project manager summary
Live delivery form template - automatically display pictures - automatically associate series products
The WebService interface writes and publishes calls to the WebService interface (I)
The applet calls the function of scanning QR code and jumps to the path specified by QR code
C list field sorting contains numbers and characters
Deep learning notes - data expansion
[2021] Spatio-Temporal Graph Contrastive Learning