7649: house number of my house, 7649: house number
7649: house number of my house
- View
- Submit
- Statistics
- Question
-
Total time limit:
-
1000 ms
-
Memory limit:
-
65536kB
-
Description
-
My family lives in a short hutong. The street number of this hutong starts from 1.
If the sum of all the street numbers is twice the number of my house, it is equal to n.
The data guarantee has a unique solution.
-
Input
-
A positive integer n. N <100000.
-
Output
-
A row contains two positive integers, which are the house number and total number of houses in the house, separated by a single space.
-
Sample Input
-
100
-
Sample output
-
10 15
-
Source
-
Typical questions of Mathematical Olympiad (sixth grade primary school) (ISBN 978-7-5445-2883-2) Chapter 2 Lecture 7 EXAMPLE 2 expand 1
-
1 #include<iostream> 2 using namespace std; 3 int now=1; 4 int tot=0; 5 int main() 6 { 7 8 int n; 9 int flag=0;10 cin>>n;11 while(1)12 {13 tot=tot+now;14 now++;15 int a;16 for(int i=1;i<=now;i++)17 {18 if(tot-i*2==n)19 {20 cout<<i<<" "<<now-1;21 flag=1;22 break;23 }24 }25 if(flag==1)break;26 }27 return 0;28 }