Algorithm


Problem Name: 2 AD-HOC - beecrowd | 2171

Problem Link: https://www.beecrowd.com.br/judge/en/problems/view/2171

Sharing with Fink

 

By Ícaro Dantas, UFCG BR Brazil

Timelimit: 1

Fink, the fox, very clever, needs to share half to half some food between him and Woody Woodpecker, but he's very hungry and thought in something very sagacious to get out of it, the division will be that way:

First, he'll put everything under the table and start to share: One for you. One for me. Two for you. One, two for me. Three for you. One, two, three for me... This way, if que initian amount of food was 12, he would finish it with 10 and the Woody Woodpecker with 2. Obs: If Fink can't finish the last division, he cans steal from the Woody Woodpecker.

 

Input

 

The input will consist in a serie of lines, each one containing a number of foods N (1 ≤ N ≤ 100000). The end of input is indicated by the number zero (0).

 

Output

 

For each input line, you must print how much food was to Fink and Woody Woodpecker at the end of the division, separated by a space.

 

 

 

Input Sample Output Sample

12

21

37

0

10 2

21 0

36 1

Code Examples

#1 Code Example with C++ Programming

Code - C++ Programming


#include <bits/stdc++.h>
using namespace std;

int main() {
	int j=0;
	long  r;
	while (cin >>r && r!=0){
		j=0;
		for(int i = 1; j+i  < = r; i++){
			j +=i;
		}
		cout << j << " " << r - j << endl;
	}
	return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
12
21
37
0

Output

x
+
cmd
10 2
21 0
36 1
Advertisements

Demonstration


Previous
#2168 Beecrowd Online Judge Solution 2168 Twilight at Portland Solution in C, C++, Java, Js and Python
Next
#2172 Beecrowd Online Judge Solution 2172 Event Solution in C, C++, Java, Js and Python