fork(2) download
  1. //Coder: Vipin Singh
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4.  
  5. #define lli long long
  6. #define pb push_back
  7. #define mp make_pair
  8. const int limit = 1000000000;
  9. const int size = 100005;
  10. int cnt[size];
  11.  
  12. int main(){
  13. lli a,b,n;
  14. scanf("%lld %lld %lld",&a,&b,&n);
  15. for(lli i=1;i*i<=limit;i++){ // this is seive
  16. lli j = ceil(1.0*a/i)*i; // first no in a-b which have i as its factor
  17. for( ; j <= b ; j+=i){
  18. lli check = j/i;
  19. if(check*i == j) // if sqrt(j)==i count only once
  20. cnt[j-a]++;
  21. else if(check > i) // each no have k and n/k as its factors , check is to make sure that we cnt for i or n/i not both
  22. cnt[j-a]+=2;
  23. }
  24. }
  25. int ans = 0;
  26. lli upto = b-a;
  27. for(lli i=0;i<=upto;i++){
  28. if(cnt[i]==n)
  29. ans++;
  30. //cout<<i+a<<" "<<cnt[i]<<endl;
  31. }
  32. printf("%d\n",ans);
  33. }
Success #stdin #stdout 0s 3532KB
stdin
1 7 2
stdout
4