题意:要将一个n维空间分成若干个小立方体,要求小n方体的边长是斐波那契数。求小n方体的数量的最小值。
分析:数据不大,暴力就可以过了。求出n条边分别最少可以写成多少个斐波那契数的和,最后将n个数相乘就是小n方体的数量的最小值。
第一步打表,斐波那契数列的第46个就超出2e9了。
求某一条边的长度n最少能写成多少个斐波那契数之和时,只需要不断减去最大的小于它的数,由下面代码中的get(int n)函数实现。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
ll fib[50];
void init()
{
fib[1] = 1;
fib[2] = 2;
for (int i = 3; i <= 46; ++i)
{
fib[i] = fib[i - 1] + fib[i - 2];
}
}
int get(int n)
{
int ans = 0;
while (n > 0)
{
for (int i = 1; i <= 46; ++i)
{
if (n < fib[i])
{
n -= fib[i - 1];
++ans;
break;
}
}
}
return ans;
}
int main()
{
init();
int t;
scanf("%d", &t);
int cnt = 0;
while (t--)
{
int n;
scanf("%d", &n);
ll ans = 1;
int temp;
for (int i = 0; i < n; ++i)
{
scanf("%d", &temp);
ans *= get(temp);
}
printf("Case %d: %lld\n", ++cnt, ans);
}
return 0;
}