【題解】ZeroJudge b230: TOI2009 第二題:方便數

【題目敘述】https://zerojudge.tw/ShowProblem?problemid=b230
【解題想法】complete search

#include <iostream>
using namespace std;

const int maxn = 1850;
int n, a[maxn], tmp, i = 1, j = 2, k = 3, cnt = 0;

int main() {
    cin >> n;
    while (1){
        while (1){
            while (1){
                tmp = i*j + i*k + j*k;
                if (tmp >= maxn) break;
                a[tmp] = 1;
                k++;
            }
            j++;
            k = j+1;
            tmp = i*j + i*k + j*k;
            if (tmp >= maxn) break;
        }
        i++;
        j = i+1;
        k = j+1;
        tmp = i*j + i*k + j*k;
        if (tmp >= maxn) break;
    }
    for (int i = 1; i < maxn; i++){
        if (a[i] == 0){
            cnt++;
            if (cnt == n){
                cout << i << "\n";
                break;
            }
        }
    }
}
#include <iostream>
using namespace std;

int n, a[70] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 13, 15, 16, 18, 21, 22, 24, 25, 28, 30, 33, 37, 40, 42, 45, 48, 57, 58, 60, 70, 72, 78, 85, 88, 93, 102, 105, 112, 120, 130, 133, 165, 168, 177, 190, 210, 232, 240, 253, 273, 280, 312, 330, 345, 357, 385, 408, 462, 520, 760, 840, 1320, 1365, 1848};

int main() {
    cin >> n;
    cout << a[n] << "\n";
}
分享本文 Share with friends