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次可以取任意多个, ...
随机推荐
- 0/1 knapsack problem
Problem statement Given n items with size Ai and value Vi, and a backpack with size m. What's the ma ...
- java拼接字符串用StringBuilder
StringBuilder builder = new StringBuilder(); String s1="abc"; for(int i=0;i<10000000;i+ ...
- C# 自动注册OCX方法
C#开发系统时,有时候会遇到调用其他语言开发的模块.如果对方提供了OCX时,就需要注册使用,但是实时时,每个客户端都注册一遍就比较麻烦.所以需要系统第一次启动时自动注册OCX. 一:C#注册OCX ...
- hdu 5952 Counting Cliques 求图中指定大小的团的个数 暴搜
题目链接 题意 给定一个\(n个点,m条边\)的无向图,找出其中大小为\(s\)的完全图个数\((n\leq 100,m\leq 1000,s\leq 10)\). 思路 暴搜. 搜索的时候判断要加进 ...
- Document类
一.类结构 org.jsoup.nodes Class Document java.lang.Object org.jsoup.nodes.Node org.jsoup.nodes.Element o ...
- win10下怎么配置以KDiff3作为merge tool和diff tool
系统环境: OS: Windows 10 Git 2.6.1.windows.1 KDiff3 0.9.98 (64 bit) 具体代码如下: git config --global --add me ...
- iptables介绍iptables和netfilter
随着互联网技术的方兴未艾,各种网络应用层出不穷,网络攻击.黑客入侵也成了网民畅游互联网的心头大患,互联网安全也愈加受到了人们的重视.网络防火墙,作为一种简单高效的互联网防御手段,逐渐成为了网民畅游网络 ...
- Cryptography I 学习笔记 --- 总结
在b站上大概的看完了Dan Boneh的密码学,对现代密码学总算有了一个粗浅的认识. 总算能在纸上手写RSA公式并且证明之了,蛤蛤. 总体的感触就是,现代密码学是一个非常博大精深的体系,我等程序员最重 ...
- (6)ASP.NET HttpServerUtility 类
HttpServerUtility 类 提供用于处理 Web 请求的 Helper 方法 https://msdn.microsoft.com/zh-cn/library/system.web.htt ...
- linux grep 搜索查找
查找关键字在哪些文件夹中的哪些文件中出现(只列出文件名称): grep -l 15386257298 */* 查找关键字在哪些文件夹中的哪些文件中出现(列出文件名称+关键字): grep -o 153 ...