hdu 2814 Interesting Fibonacci
pid=2814">点击此处就可以传送 hdu 2814
题目大意:就是给你两个函数,一个是F(n) = F(n-1) + F(n-2),
F(0) = 0, F(1) = 1;
还有一个是 G(n) = G(n-1)^F(a^b);
G(1) = F(a^b);
求G(n) % c;
范围:A, B, N, C (10<=A, B<2^64, 2<=N<2^64, 1<=C<=300)
注意了:c的范围是1<= C <= 300,所以说它一定会有循环 节:
解题思路: 首先算G(1) = F(a^b),设a^b的循环节是len;
F(a^b)%c = F(a^b%len)%c;
一边加一边取余
然后算G(n)%c = F(a^b)^(F(a^b)^(n-1)) % c;
G(n)%c = F(a^b)^(F(a^b)^(n-1)%phi(c)+phi(c))%c;
F(a^b)^(n-1)%phi(c)+phi(c) == (F(a^b)%phi(c)^(n-1))+phi(c)
F(a^b)%phi(c) 有循环节。同上,详细详见代码
上代码:
/*
2015 - 8 - 16 下午
Author: ITAK
今日的我要超越昨日的我,明日的我要胜过今日的我,
以创作出更好的代码为目标,不断地超越自己。
*/
#include <iostream>
#include <cstdio>
using namespace std;
//高速幂取余
int quick_mod(int a, unsigned long long b, int c)
{
int ans = 1;
a %= c;
while(b)
{
if(b & 1)
ans = (ans*a) % c;
b >>= 1;
a = (a*a) % c;
}
return ans;
}
//欧拉函数
int Phi(int m)
{
int ans = m;
for(int i=2; i*i<=m; i++)
{
if(m%i == 0)
ans -= ans/i;
while(m%i == 0)
m /= i;
}
if(m > 1)
ans -= ans/m;
return ans;
}
//公式:x^y % c == x^(y%phi(c)+phi(c))%c;
int data[90005],data1[90005];
int main()
{
//注意不要用long long,用unsigned long long
unsigned long long a, b, n;
int c, c1, t, n1, n2, tmp;
int g[10], len=0, len_c=0, len_e=0;
scanf("%d",&t);
for(int k=1; k<=t; k++)
{
//cin>>a>>b>>n>>c;
scanf("%lld%lld%lld%d",&a,&b,&n,&c);
if(c == 1)
{
printf("Case %d: 0\n",k);
continue;
}
data[0]=0, data[1]=1;
data1[0]=0, data1[1]=1;
for(int i=2; i<90005; i++)
{
data[i] = (data[i-1]+data[i-2])%c;
if(data[i]==1 && data[i-1]==0)
{
len = i-1;//c的循环节
break;
}
}
c1 = Phi(c);
if(c1 > 1)
{
for(int i=2; i<90005; i++)
{
data1[i] = (data1[i-1]+data1[i-2])%c1;
hdu 2814 Interesting Fibonacci的更多相关文章
- Interesting Fibonacci(hdu 2814)
Interesting Fibonacci Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- hdu Interesting Fibonacci
Interesting Fibonacci Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- hdu 5895 广义Fibonacci数列
Mathematician QSC Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Othe ...
- HDU 2814 斐波那契循环节 欧拉降幂
一看就是欧拉降幂,问题是怎么求$fib(a^b)$,C给的那么小显然还是要找循环节.数据范围出的很那啥..unsigned long long注意用防爆的乘法 /** @Date : 2017-09- ...
- hdu 3304 Interesting Yang Yui Triangle
hdu 3304 Interesting Yang Yui Triangle 题意: 给出P,N,问第N行的斐波那契数模P不等于0的有多少个? 限制: P < 1000,N <= 10^9 ...
- HDU 1588 Gauss Fibonacci(矩阵高速幂+二分等比序列求和)
HDU 1588 Gauss Fibonacci(矩阵高速幂+二分等比序列求和) ACM 题目地址:HDU 1588 Gauss Fibonacci 题意: g(i)=k*i+b;i为变量. 给出 ...
- hdu 2426 Interesting Housing Problem 最大权匹配KM算法
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2426 For any school, it is hard to find a feasible ac ...
- 【HDU 2855】 Fibonacci Check-up (矩阵乘法)
Fibonacci Check-up Problem Description Every ALPC has his own alpc-number just like alpc12, alpc55, ...
- hdu 2516(Fibonacci博弈博弈)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2516 Problem Description 1堆石子有n个,两人轮流取.先取者第1次可以取任意多个, ...
随机推荐
- Codeforces Round #315 (Div. 2) B 水题强行set
B. Inventory time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- springboot 2.0配置集成thymeleaf的坑
Servlet.service() for servlet [dispatcherServlet] in context with path [] java.lang.NoClassDefFoundE ...
- IOS YYKit 源码解析
https://blog.csdn.net/weixin_33874713/article/details/87034047
- 简单的实现web聊天界面,一对一
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...
- UVa 11234 The Largest Clique
找最长的连接的点的数量.用tarjan缩点,思考可知每一个强连通分量里的点要么都选,要么都不选(走别的路),可以动规解决. #include<iostream> #include<c ...
- jquery.slider jquery滑块插件
原文发布时间为:2011-03-08 -- 来源于本人的百度文章 [由搬家工具导入] http://jqueryui.com/demos/slider jquery滑块插件
- datatable导出到Word / Excel / PDF / HTML .NET
原文发布时间为:2011-01-21 -- 来源于本人的百度文章 [由搬家工具导入] IEnumerable - DataTable Export to Word / Excel / PDF / HT ...
- 呵呵呵呵。。。系统还原了,终于可以用IE登陆百度了
原文发布时间为:2009-12-19 -- 来源于本人的百度文章 [由搬家工具导入] 呵呵呵呵。。。今天终于有时间把系统还原了,终于可以用IE登陆百度了
- the project was not built since its build……
[问题描述] 用eclipse编译程序时,出现下面错误: The project was not built since its build path is incomplete. Cannot fi ...
- luogu P3147 [USACO16OPEN]262144
题目描述 Bessie likes downloading games to play on her cell phone, even though she doesfind the small to ...