Go to diff to previous submission
#include <iostream> #include <string> #include <cstdlib> #include <cstdio> #include <vector> using namespace std; int main () { unsigned long n, x, y, pocet; n = x = y = pocet = 0; string input; vector<unsigned long> pouzite; bool nasel = false; while (cin) { cin >> input; n = atoi(input.c_str()+2); x = n+1; if (n == 0) { cout << 0 << "\n"; continue; } if (n == 1) { cout << 1 << "\n"; continue; } while (float((x*n))/(x-n) > n+1) { if((x*n)%(x-n)==0) { y = x*n/(x-n); //if (y < x) break; nasel = false; for (vector<unsigned long>::iterator i = pouzite.begin(); i != pouzite.end(); i++) { if ((*i) == y) { nasel = true; break; } } if (!nasel) { pocet++; pouzite.push_back(x); } //if (y == x) break; } x++; } y = 0; x = 0; cout << pocet << "\n"; pocet = 0; } return 0; }
--- c5.s530.cteam016.fl.cpp.0.f1.cpp +++ c5.s648.cteam016.fl.cpp.0.f1.cpp @@ -3,4 +3,5 @@ #include <cstdlib> #include <cstdio> +#include <vector> using namespace std; @@ -11,4 +12,6 @@ n = x = y = pocet = 0; string input; + vector<unsigned long> pouzite; + bool nasel = false; while (cin) @@ -17,4 +20,9 @@ n = atoi(input.c_str()+2); x = n+1; + if (n == 0) + { + cout << 0 << "\n"; + continue; + } if (n == 1) { @@ -22,14 +30,25 @@ continue; } - while (true) + while (float((x*n))/(x-n) > n+1) { if((x*n)%(x-n)==0) { y = x*n/(x-n); - if (y < x) break; - - pocet++; - - if (y == x) break; + //if (y < x) break; + nasel = false; + for (vector<unsigned long>::iterator i = pouzite.begin(); i != pouzite.end(); i++) + { + if ((*i) == y) + { + nasel = true; + break; + } + } + if (!nasel) + { + pocet++; + pouzite.push_back(x); + } + //if (y == x) break; } x++;