fork download
  1. def gcd(x, y):
  2. while y != 0:
  3. (x, y) = (y, x % y)
  4. return x
  5. l,r,p,q=map( int , raw_input().split() )
  6. t=1
  7. ans=0
  8. while p**t <= r :
  9. z=t+1
  10. tavanp=p ** t
  11. tavanp1=p ** z
  12. tavanq=q ** t
  13. lcm=tavanp*tavanq/(gcd(tavanp,tavanq))
  14. lcm3=(tavanp1*tavanq)/(gcd(tavanp1,tavanq))
  15. plus=(r/tavanp) - ( (l-1)/tavanp )
  16. minus=(r/lcm) - ( (l-1)/lcm )
  17. minus1=(r/tavanp1) - ( (l-1)/tavanp1 )
  18. plus1=(r/lcm3) - ( (l-1)/lcm3 )
  19. ans=ans+plus-minus-minus1+plus1
  20. t=t+1;
  21. print(ans);
  22.  
  23.  
Runtime error #stdin #stdout #stderr 0.02s 9016KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "prog.py", line 5, in <module>
EOFError: EOF when reading a line