Untitled
unknown
c_cpp
2 years ago
669 B
5
Indexable
#include <stdio.h> int f(int n) { int total = 0, bottle = 0, borrow = 0, flag = 0; if (n % 3 == 1) { bottle += 2; borrow = 2; } else if (n % 3 == 2) { bottle += 1; borrow = 1; } else { flag = 1; } while (1) { int temp; total += n; if (n + bottle == borrow) { break; } else if (flag && n == 1) { break; } temp = bottle; bottle = (n + bottle) % 3; n = (n + temp) / 3; } return total; } void main() { int M, N, count = 0; scanf("%d", &M); for (int i = 0; i < M; i++) { scanf("%d", &N); if (i == 0) { printf("%d", f(N)); } else { printf(" %d", f(N)); } } }
Editor is loading...