// Give N and K, calculate k different positive integers, so that the number of K-1 can constitute the number of workers, k Number and N. The output is yes, and the output is no. # Include <stdio. h> # include <string. h> # include <algorithm> # include <math. h> using namespace STD; int N, K; bool judge (INT num) {int YY = num * num; // The sum of the number of K-1 int KK = N-yy; if (KK = 0) return false; int sum = 0; int COT = 0; For (INT I = 0; I <K-2; I ++) {cot ++; if (COT = KK) cot ++; sum + = cot;} If (sum + KK> = N) return false; int need = N-sum-kk; // Number of K-1 if (need <= Cot) return false; cot ++; If (KK = cot | KK = cot + 1) {If (need = K K) return false;} return true;} bool slove () {int M = SQRT (N * 1.0); For (INT I = m; I> = 1; I --) {If (Judge (I) return true;} return false;} int main () {While (~ Scanf ("% d", & N, & K) {If (slove () printf ("Yes \ n "); else printf ("NO \ n");} return 0 ;}
HDU 4982 goffi and squary partition (enumeration)