当前位置:网站首页>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;
}
边栏推荐
猜你喜欢

Processing polyhedron change

【网络是怎么连接的】第一章:浏览器生成消息

倍福通过CTU和TON实现时间片大小和数量的控制

Processing function translate (mousex, mousey) learning

Processsing mouse interactive learning

Unit practice experiment 8 - using cmstudio to design microprogram instructions based on basic model machine (1)

Do you know the limitations of automated testing?

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

机器学习笔记 - 时间序列的季节性

National standard gb28181 protocol easygbs cascaded universal vision platform, how to deal with live message 403?
随机推荐
First knowledge - Software Testing
Analysis and protection of heart blood dripping vulnerability (cve-2014-0160)
Learning Processing Zoog
map 取值
Openlayers drawing dynamic migration lines and curves
MariaDB study notes
心脏滴血漏洞(CVE-2014-0160)分析与防护
组合模式(Composite )
QT . Establishment and use of pri
HDU1724[辛普森公式求积分]Ellipse
National standard gb28181 protocol easygbs video platform TCP active mode streaming exception repair
Source code learning: atomicinteger class code internal logic
Electron official docs series: Processes in Electron
机器学习笔记 - 时间序列的季节性
倍福PLC旋切基本原理和应用例程
自动化测试的局限性你知道吗?
H - Sumsets POJ 2229
Explain C language 10 in detail (C language series)
To solve the difficulties of small and medium-sized enterprises, Baidu AI Cloud makes an example
利用scrapy爬取句子迷网站优美句子存储到本地(喜欢摘抄的人有福了!)