fork download
  1. #include <bits/stdc++.h>
  2. #define fr(a,b,c) for(int a = b, _ = c; a < _; a++)
  3.  
  4. using namespace std;
  5. typedef long long ll;
  6. int main(){
  7. ll l,r,k,a = 1;
  8. bool ok;
  9. cin >> l >> r >> k;
  10. while(a <= r){
  11. if(a >= l){
  12. ok = true;
  13. cout << a << " ";
  14. }
  15. if(a*k <= r)a*=k;
  16. else break;
  17. }
  18. if(!ok)cout << "-1";
  19. return 0;
  20. }
Success #stdin #stdout 0s 15224KB
stdin
1 10 2
stdout
1 2 4 8