Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. long long powl(int a, int n) {
  4. if (n <= 1) return 1;
  5. if (n % 2 == 1) return powl (a, n-1) * a;
  6. else {
  7. int b = powl (a, n/2);
  8. return b * b;
  9. }
  10. }
  11. long long log( long long n, long long a){
  12. if(n == 1) return 1;
  13. return 1 + log(n/a, a);
  14. }
  15. long long geoma(long long cnt, long long a , long long b){
  16. return (a * (powl(b,cnt) - 1) / (b - 1));
  17. }
  18. int main(){
  19. freopen("in.txt","r",stdin);
  20. long long n ,a ,b,mx;
  21. cin >> n >> a >> b >> mx;
  22. if (b == 1){
  23. cout << min(mx/a , n);
  24. return 0;
  25. }
  26. long long ans = 0;
  27.  
  28.  
  29. // cnt =
  30. long long cnt = log(9 * mx + (a/(b-1)), b);
  31. if (cnt > n ){
  32. cnt = n;
  33. }
  34. while(cnt){
  35. if (geoma(cnt , a , b) <= mx){
  36. cout << cnt;
  37. return 0;
  38. }
  39. cnt --;
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement