Advertisement
Ritam_C

Botanical Garden CP101

Feb 14th, 2021
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.45 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main(){
  5.     ios_base::sync_with_stdio(false);
  6.     cin.tie(NULL);
  7.     int n, k;
  8.     cin >> n >> k;
  9.  
  10.     if(n <= 2){
  11.         cout << 1 << "\n";
  12.     } else{
  13.         int64_t seeds = k, plants = 1;
  14.         for(int i = 3; i <= n; i++){
  15.             int64_t tmp = plants;
  16.             plants += seeds;
  17.             seeds = tmp*k;
  18.         }
  19.  
  20.         cout << plants << "\n";
  21.     }
  22.  
  23.     return 0;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement