Last active
May 30, 2017 07:21
-
-
Save magicsih/3be008b418fba2300d1f8e68c0aece4b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //============================================================================ | |
| // Name : MadProgression.cpp | |
| // Author : magicsih | |
| // Version : | |
| // Copyright : | |
| // Description : Mad Progression in C++, Ansi-style | |
| //============================================================================ | |
| #include <iostream> | |
| #include <fstream> | |
| using namespace std; | |
| int main() { | |
| long long position = 4; | |
| std::ifstream fin; | |
| fin.open("input.txt"); | |
| fin >> position; | |
| fin.close(); | |
| long long accumulator = 1; | |
| long long supplement = 1; | |
| while (accumulator < position) { | |
| accumulator += supplement; | |
| if (accumulator <= position) { | |
| supplement++; | |
| } | |
| } | |
| std::ofstream fout; | |
| fout.open("output.txt"); | |
| fout << supplement; | |
| fout.close(); | |
| return 1; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Algorithm : Mad Progression
Condition
1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, ...
Input
4
Output
3