swexpert
[swea] 1265. 달란트2 (C++, 수학?)
해랑쓰
2021. 9. 30. 14:51
728x90
반응형
묶음의 개수 P가 정해졌을 때 각 묶음의 달란트를 곱한 수가 크려면 각 묶음의 달란트가 최대한 골고루 분배되어야 된다는 것을 알 수 있다.
일단 달란드 개수 N/P는 각 묶음의 최소 달란트 개수로 초기화해준다.
그러면 N%P만큼의 분배되지 않은 달란트가 남을 것인데 해당 달란트들은 골고루 +1씩 해줘서 나눠준 후 곱하면 된다.
#define _CRT_SECURE_NO_DEPRECATE
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
int n, t, p;
long long ans;
int main(void) {
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> t;
for (int tc = 1; tc <= t; tc++)
{
ans = 1;
cin >> n >> p;//p는 묶음의 수
vector<int> v;
for(int i=0;i<p;i++){
v.push_back(n / p);//각 묶음 초기 개수
}
for (int i = 0; i < n%p; i++) {
v[i]++;
}
for (int i = 0; i < p; i++) {
ans *= v[i];
}
cout << "#" << tc << " " << ans << "\n";
}
return 0;
}
728x90
반응형