1 solutions
-
0
C :
#include <stdio.h> int main() { int x,sum; while(scanf("%d",&x)!=EOF) { sum=x; while(x>=3) { sum+=x/3; x=x/3+x%3; } printf("%d\n",sum); } return 0; }C++ :
# include <iostream> using namespace std; int main() { int n, j = 0, k; while(cin >> n) { int j = 0; k = n; while(n >= 3) { j += n / 3; n = n / 3 + n % 3; } cout << j + k << endl; } return 0; }Java :
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); while(true) { int amount = in.nextInt(); int cnt = amount; int getNumber = 0; while(true) { getNumber = cnt / 3; amount += getNumber; cnt = cnt % 3 + getNumber; if(cnt < 3) { break; } } System.out.println(amount); } } }
- 1
Information
- ID
- 18623
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- (None)
- Tags
- (None)
- # Submissions
- 0
- Accepted
- 0
- Uploaded By