P10095 [ROIR 2023 Day 1] 斐波那契乘积

# [ROIR 2023 Day 1] 斐波那契乘积

## 题目背景

翻译自 [ROIR 2023 D1T2](https://neerc.ifmo.ru/school/archive/2022-2023/ru-olymp-regional-2023-day1.pdf)。

斐波那契数指斐波那契数列($f_0=1,f_1=1,f_i=f_{i-2}+f_{i-1}$)中出现的数。

## 题目描述

给定一个自然数 $n$,求出将其表示为大于 $1$ 的斐波那契数的乘积的方式数量。

## 输入格式

第一行一个数 $t$,表示数据组数。

接下来 $t$ 行,每行输入一个数 $n$。

## 输出格式

对于每组测试数据,输出一个数表示答案。

## 样例 #1

### 样例输入 #1

```
5
2
7
8
40
64
```

### 样例输出 #1

```
1
0
2
2
3
```

## 提示

样例解释:
- $2=2$。
- $7$ 无法被表示为斐波那契乘积。
- $8=8=2\times2\times2$。
- $40=5\times8=2\times2\times2\times5$。
- $64=8\times8=2\times2\times2\times8=2\times2\times2\times2\times2\times2$。

本题使用捆绑测试。

| 子任务编号 | 分值 | $2\le n\le$ |
| :----------: | :----------: | :----------: |
| $1$ | $15$ | $100$ |
| $2$ | $17$ | $10^5$ |
| $3$ | $9$ | $n$ 是 $2$ 的整数次幂 |
| $4$ | $38$ | $10^9$ |
| $5$ | $21$ | $10^{18}$ |

对于所有数据,$1\le t\le50$,$2\le n\le10^{18}$。

#include<bits/stdc++.h>
using namespace std;
long long f[100],s;
void g(int x,long long y){
	if(y==1){
		s++;
		return;
	}
	if(x==87)return;
	if(y%f[x]==0)g(x,y/f[x]);
	g(x+1,y);
}
int main()
{
	f[0]=1,f[1]=1;
	for(int i=2;i<=86;i++){
		f[i]=f[i-1]+f[i-2];
	}
	int t;
	long long n;
	scanf("%d",&t);
	while(t--){
		scanf("%lld",&n);
		s=0;
		g(2,n);
		printf("%d\n",s);
	}
	return 0;
}
  • 8
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值