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 1118. Nontrivial Numbers

Show all messages Hide all messages

#include <iostream>
using namespace std;
int main() {
    long long i, j, iDel; long long biggestV = 9999999, biggestDel = 9999999;
    cin >> i >> j;
    if (i == 1) {
        cout << 1;
        return 0;
    }
    else if (i == j) {
        cout << i;
        return 0;
    }
    else if (i + 1 == j) {
        cout << (j % 2 != 0 ? j : i);
        return 0;
    }
    for (long long iV = j % 2 != 0 ? j : j-1; iV >= i; iV -= 2) {
        for (iDel = j / 3 + 1; iDel >= 1; iDel--) {
            if (iV%iDel == 0) {
                if (iDel < biggestDel) {
                    biggestDel = iDel;
                    biggestV = iV;
                }
                break;
            }
        }
        if (iDel == 1) {
            cout << iV;
            return 0;
        }
    }
    cout << biggestV;
}
In the main cycle you doesn't compare trivialities, you search the smallest biggest divisor in the weird range instead. Could you please show the mathematical proof of your main cycle?

Edited by author 31.03.2020 14:11

Edited by author 31.03.2020 14:12
Hi.Did you solve this problem?