ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1120. Sum of Sequential Numbers

WA on test nr.4
Posted by Climova Olga 24 Feb 2015 13:12
Sorry for russian comments, I don't speak English well. Why WA? (system("pause"); is only for checking, of course)
#include <iostream>
using namespace std;

int main()
{
    unsigned long N, P, A;
    cin >> N;
    for (A = 1; A <= N; A++) // чтобы P было максимальным, начинаем с меньшего А
    {    // прокручиваем P с N/A вниз, т.к. вроде бы это минимальное число с которого следует начинать
        for (P = N / A; P*A + P*(P - 1) / 2 > N; P--);
        if (P*A + P*(P - 1) / 2 == N) // если нашли - останавливаемся
            break;
    }
    cout << A << ' ' << P;
    system("pause");
    return 0;
}

Edited by author 24.02.2015 13:16