forked from mintuhouse/spoj-solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
530-divisors.cpp
75 lines (68 loc) · 1.43 KB
/
530-divisors.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include<iostream>
#include<math.h>
#include<vector>
using namespace std;
vector<int> primes;
bool div[1000001];
vector<int> property;
bool isprime(int n){
int r=sqrt(n);
for(int i=2;i<=r;i++){
if(n%i==0) return false;
}
return true;
}
bool issatisy(int n){
if(div[n]!=0) return div[n];
int N=n;
vector<int>::iterator it;
for (it=primes.begin(); it<primes.end(); it++){
int i=*it,j=0;
while(n%i==0){
n=n/i;
j++;
}
if(j==1){
div[N]=issatisy(n);
return div[N];
}else if (j>1){
div[N]=0;
return 0;
}
}
div[N]=0;
return 0;
}
int main(){
int C,K,Ot;
long long high,low;
float rt;
int s1,s2;
bool p[1000001];
for(int i=0;i<=1000000;i++) p[i]=1;
for(int i=2;i<=1000000;i++){
if(p[i]==0) continue;
if(isprime(i)){
primes.push_back(i);
for(int j=2*i;j<=1000000;j+=i){
p[j]=0;
}
}
}
for(int i=1;i<=100000;i++) { div[i]=0;}
for(int i=100000;i>=1;i--) { div[i]=numdivisors(i);}
return 0;
cin>>C;
for(int i=0;i<C;i++){
Ot=0;
cin>>K>>low>>high;
rt=sqrt(low); s1=rt;
if((float)s1!=rt) s1++;
s2=sqrt(high);
for(int j=s1;j<=s2;j++){
if(div[j]==K)Ot++;
}
cout<<Ot<<endl;
}
return 0;
}