当前位置:网站首页>Uva11582 [fast power]colossal Fibonacci numbers!
Uva11582 [fast power]colossal Fibonacci numbers!
2022-06-26 13:09:00 【YJEthan】
The question :f[] For fiboracci series , I want you to ask f[a^b]%n;
Ideas : Using the nature of fiboracci , Find the cyclic section of the remainder , if f[i]==1&&f[i-1]==0, Then the cycle section is i-1;
seek a^b With a fast power
notes :UVAunsigned long long Input and output with %llu
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
typedef unsigned long long ull;
ull qpow(ull a,ull b,ull cnt)
{
a=a%cnt;
ull ans=1;
while(b>0)
{
if(b%2==1)
ans=a*ans%cnt;
b/=2;
a=a*a%cnt;
}
return ans;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
ull a,b,n;
scanf("%llu%llu%llu",&a,&b,&n);
ull i;
vector<ull>fib;
fib.push_back(0);
fib.push_back(1);
ull cnt=0;
for(i=2;i<=n*n;i++)
{
fib.push_back((fib[i-1]+fib[i-2])%n);
cnt++;
if(fib[i]==1&&fib[i-1]==0)
break;
}
if(n!=1)
printf("%llu\n",fib[qpow(a,b,cnt)]);
else printf("0\n");
}
return 0;
}
边栏推荐
- Analysis and protection of heart blood dripping vulnerability (cve-2014-0160)
- May product upgrade observation station
- Learning Processing Zoog
- F - Charm Bracelet
- 中科软外包一面
- Digital signal processing -- Design of linear phase type (Ⅰ, Ⅲ) FIR filter (1)
- 黑马笔记---常用API
- [geek challenge 2019] rce me 1
- KVM video card transparent transmission -- the road of building a dream
- 倍福NC轴状态转移图解析
猜你喜欢

MariaDB study notes

倍福PLC基于NT_Shutdown实现控制器自动关机重启

Detailed explanation of C const: definition and use of C constant

倍福TwinCAT通过Emergency Scan快速检测物理连接和EtherCAT网络

. Net Maui performance improvement

首批通过!百度智能云曦灵平台获信通院数字人能力评测权威认证

详细讲解C语言10(C语言系列)

scrapy——爬取漫画自定义存储路径下载到本地

Power Designer - Custom Comment button

Processing function translate (mousex, mousey) learning
随机推荐
5月产品升级观察站
What should the software test report include? Interview must ask
Angle de calcul POSTGIS
原型模式(prototype)
Use the script to crawl the beautiful sentences of the sentence fan website and store them locally (blessed are those who like to excerpt!)
机器学习笔记 - 时间序列的季节性
倍福PLC通过MC_ReadParameter读取NC轴的配置参数
How does easygbs solve the abnormal use of intercom function?
First pass! Baidu AI Cloud Xiling platform has obtained the authoritative certification of digital human ability evaluation from the Institute of information technology
map 取值
自动化测试的局限性你知道吗?
postgis計算角度
倍福将EtherCAT模块分到多个同步单元运行--Sync Units的使用
倍福PLC实现绝对值编码器原点断电保持---bias的使用
Deeply analyze the differences between dangbei box B3, Tencent Aurora 5S and Xiaomi box 4S
P5733 [deep foundation 6. example 1] automatic correction
倍福Ethercat模块网络诊断和硬件排查的基本方法
The El form item contains two inputs. Verify the two inputs
倍福PLC选型--如何看电机是多圈绝对值还是单圈绝对值编码器
UVa11582 [快速幂]Colossal Fibonacci Numbers!