Skip to content

Instantly share code, notes, and snippets.

@magicsih
Last active May 30, 2017 07:21
Show Gist options
  • Save magicsih/3be008b418fba2300d1f8e68c0aece4b to your computer and use it in GitHub Desktop.
Save magicsih/3be008b418fba2300d1f8e68c0aece4b to your computer and use it in GitHub Desktop.
//============================================================================
// 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;
}
@magicsih
Copy link
Author

Algorithm : Mad Progression

Condition

1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, ...

Input

4

Output

3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment