hdu-2814-Interesting Fibonacci-斐波那契循环节
来源:互联网 发布:oracle sql调优技巧 编辑:程序博客网 时间:2024/05/16 23:38
哇塞,我竟然2A了。。。。没有1A纯粹是脑残了。。
求:F(a^b)^(F(a^b) ^ (n-1))%c
既是求F(a^b)^(F(a^b) ^ (n-1)%phi[c]+phi[c])%c
先求x=F(a^b)%phi[c],有循环节,直接找到循环节就OK。
然后求y=F(a^b)%c,同求x,循环节。
然后问题就变成求y^(x^(n-1)%phi[c]+phi[c])
直接套两次快速幂取模就OK。
#include <iostream>
#include<stdio.h>
#include<vector>
#include<queue>
#include<stack>
#include<string.h>
#include<algorithm>
#include<math.h>
using namespace std;
#define LL unsigned __int64
#define lcm(a,b) (a*b/gcd(a,b))
//O(n)求素数,1-n的欧拉数
#define N 110000
struct math_use
{
LL euler(LL x)
{
LL i, res = x;
for (i = 2; i*i <= x; i++)
if (x%i == 0)
{
res = res / i*(i - 1);
while (x%i == 0)
x /= i;
}
if (x > 1)
res = res / x*(x - 1);
return res;
}
//a^b%c
LL q_mod(LL a,LL b,LL n)
{
LL ret=1;
LL tmp=a;
while(b)
{
//基数存在
if(b&0x1) ret=ret*tmp%n;
tmp=tmp*tmp%n;
b>>=1;
}
return ret;
}
} M;
int smod[330];
int eur[330];
LL s_mod(int mod)
{
LL a1,a2,a3,tmp;
a1=0;
a2=1;
a3=1;
LL ans=1;
while(a2!=0||a3!=1)
{
tmp=(a2+a3)%mod;
a2=a3;
a3=tmp;
ans++;
}
return ans;
}
void init()
{
smod[1]=1;
eur[1]=M.euler(1);
for(int i=2; i<=300; i++)
{
smod[i]=s_mod(i);
eur[i]=M.euler(i);
}
}
LL get_fib(int x,int mod)
{
if(x==0)return 0;
LL a1,a2,a3,tmp;
a1=0;
a2=a3=1;
x--;
while(x--)
{
tmp=(a2+a3)%mod;
a2=a3;
a3=tmp;
}
return a2;
}
LL fib(LL a,LL b,LL mod)
{
LL ans=1;
int yu=smod[mod];
LL s=M.q_mod(a%yu,b,yu);
return get_fib(s,mod);
}
int main()
{
LL a,b,n,c;
init();
LL T;
cin>>T;
int cas=0;
while(T--)
{
cas++;
cin>>a>>b>>n>>c;
if(c==1)
{
printf("Case %d: 0\n",cas);
continue;
}
LL x,y;
LL mod,mod1;
mod=c;
mod1=eur[c];
x=fib(a,b,mod1);
y=fib(a,b,mod);
LL p=M.q_mod(x,(n-1)%eur[mod1]+eur[mod1],mod1);
LL ans=M.q_mod(y,p+mod1,mod);
printf("Case %d: ",cas);
cout<<ans<<endl;
}
return 0;
}
- hdu-2814-Interesting Fibonacci-斐波那契循环节
- HDU 2814 Interesting Fibonacci 循环节
- HDU 2814 - Interesting Fibonacci (Fibonacci性质 + 循环节)
- hdu 2814 Interesting Fibonacci
- hdu 2814 Interesting Fibonacci
- hdu 2814 Interesting Fibonacci
- hdu 2814 Interesting Fibonacci
- UVA11582Colossal Fibonacci Numbers!(斐波那契找循环节)
- HDU2813Interesting Fibonacci(斐波那契数列+循环节)
- HDOJ1021 Fibonacci Again斐波那契找循环
- Uva11582 Colossal Fibonacci Numbers! (数论、斐波那契循环节)
- [斐波那契循环节 搜索] BZOJ 4294 [PA2015]Fibonacci
- hdu 1708 Fibonacci String 斐波那契数列
- HDU 4786 Fibonacci Tree 斐波那契树
- HDU 1588 Gauss Fibonacci(矩阵 + 斐波那契)
- HDU 1708 Fibonacci String(斐波那契字串)
- hdu 5167 Fibonacci(DFS,剪枝,斐波那契)
- HDU - 2855 Fibonacci Check-up 斐波那契矩阵
- 14、B树、B+树的概念及用途
- android应用开发中的图片缓存系统
- krpano 教程 - display 标签中文说明
- 【ORACLE】AWR报告的生成和简单分析方法
- 新浪 ip 地址库
- hdu-2814-Interesting Fibonacci-斐波那契循环节
- 关于 xcode5 每次修改代码,都要先clean,重新编译才有效的解决方法汇总
- 获取任务栏所有正在运行程序
- quartus时序分析文档理解与翻译(2) ——一个设置约束的例程
- IP地址API
- C++解析xml--tinyxml--DOM模型
- PHP源码加密
- mvc Razor 视图中找不到 ViewBag的定义
- inet_ntoa 和inet_addr函数