Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cmath>
- #include <cstdio>
- #include <vector>
- #include <iostream>
- #include <algorithm>
- using namespace std;
- bool smooth(int n, int p)
- {
- if (n%2==0)
- return (p>=2);
- for (int i=3;i*i<=n;i=i+2)
- if (n%i==0)
- return (i<=p);
- return (n <= p);
- }
- bool jagged(int n, int p)
- {
- if (n%2==0)
- return (p<=2);
- for (int i=3;i*i<=n;i=i+2)
- if (n%i==0)
- return (i>=p);
- return (n >= p);
- }
- int main()
- {
- int n,f,l,p,count;
- cin>>n;
- while(n--)
- {
- count=0;
- cin>>f>>l>>p;
- for(int i=f;i<=l;i++)
- {
- if(jagged(i,p))
- count++;
- else if(smooth(i,p))
- count++;
- }
- cout<<count<<endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement