#include <stdio.h>
int main() {
int K, M;
scanf("%d %d", &K, &M);
int trees = 1; // Initially one tree with value 2
for (int i = 0; i < K; i++) {
int V = trees % M;
trees -= 1; // Cut the tree
trees += (V + 1) % M; // Plant (V+1)%M trees
}
printf("%d\n", trees);
return 0;
}
C language
Telegram:- @allcoding1
int main() {
int K, M;
scanf("%d %d", &K, &M);
int trees = 1; // Initially one tree with value 2
for (int i = 0; i < K; i++) {
int V = trees % M;
trees -= 1; // Cut the tree
trees += (V + 1) % M; // Plant (V+1)%M trees
}
printf("%d\n", trees);
return 0;
}
C language
Telegram:- @allcoding1
👍14🥰4
🎯Cisco Hiring Graduate Trainee
Qualifications: Bachelor's/ Master's
Salary: 7 - 9 LPA (Expected)
Batch: 2020/ 2021/ 2022/ 2023/ 2024
Location: PAN India
Apply Now:- http://www.joboffersadda.com
Telegram:- @allcoding1
Qualifications: Bachelor's/ Master's
Salary: 7 - 9 LPA (Expected)
Batch: 2020/ 2021/ 2022/ 2023/ 2024
Location: PAN India
Apply Now:- http://www.joboffersadda.com
Telegram:- @allcoding1
👍6