DdoubleJ
2018. 6. 28. 17:04
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | #include <stdio.h> #include <math.h> unsigned long long min = 2e9; unsigned long long cal(long long a, long long b, long long n, long long r, long long c) { long long temp; if(r>c) temp=a*(r - c) + b*(n - (r*c)); else temp= a*(c - r) + b*(n - (r*c)); return temp; } int main(void) { int test_case; scanf("%d\n", &test_case); for (int z = 1; z<= test_case; z++) { min = 2e9; int n, a, b; scanf("%d%d%d", &n,&a,&b); for (int i = 1; i <=sqrt(n); i++) { for (int j = sqrt(n) /2; j <= n; j++) { if (i*j <= n) { unsigned long long temp = cal(a, b, n, i, j); if (temp < 0) { continue; } if (temp < min) { min = temp; } } else { break; } } } printf("#%d %llu\n", z, min); } return 0; } | cs |