Interesting Fibonacci

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1071    Accepted Submission(s): 229

Problem Description
In
mathematics, the Fibonacci numbers are a sequence of numbers named
after Leonardo of Pisa, known as Fibonacci (a contraction of filius
Bonaccio, "son of Bonaccio"). Fibonacci's 1202 book Liber Abaci
introduced the sequence to Western European mathematics, although the
sequence had been previously described in Indian mathematics.
  The
first number of the sequence is 0, the second number is 1, and each
subsequent number is equal to the sum of the previous two numbers of the
sequence itself, yielding the sequence 0, 1, 1, 2, 3, 5, 8, etc. In
mathematical terms, it is defined by the following recurrence relation:

That
is, after two starting values, each number is the sum of the two
preceding numbers. The first Fibonacci numbers (sequence A000045 in
OEIS), also denoted as F[n];
F[n] can be calculate exactly by the following two expressions:


A
Fibonacci spiral created by drawing arcs connecting the opposite
corners of squares in the Fibonacci tiling; this one uses squares of
sizes 1, 1, 2, 3, 5, 8, 13, 21, and 34;

So you can see how interesting the Fibonacci number is.
Now AekdyCoin denote a function G(n)

Now your task is quite easy, just help AekdyCoin to calculate the value of G (n) mod C
 
Input
The
input consists of T test cases. The number of test cases (T is given in
the first line of the input. Each test case begins with a line
containing A, B, N, C (10<=A, B<2^64, 2<=N<2^64,
1<=C<=300)
 
Output
For
each test case, print a line containing the test case number( beginning
with 1) followed by a integer which is the value of G(N) mod C
 
Sample Input
1
17 18446744073709551615 1998 139
 
Sample Output
Case 1: 120
 
Author
AekdyCoin
 思路:欧拉函数;
G(n)= F(a^b)^((F(a^b))^(N-1));然后,找一下数列的循环节,然后应为a^b>300,所以直接用欧拉降幂,((F(a^b)^(N-1))%oula[C] + oula[C]);因为F(a^b)^(N-1) > oula[C];
这样幂数就就降下来了。
  1 #include<stdio.h>
2 #include<algorithm>
3 #include<stdlib.h>
4 #include<queue>
5 #include<iostream>
6 #include<string.h>
7 #include<math.h>
8 using namespace std;
9 typedef unsigned long long LL;
10 bool prime[400];
11 int ans[400];
12 int oula[400];
13 int ff[30];
14 typedef struct node
15 {
16 LL m[2][2];
17 node()
18 {
19 memset(m,0,sizeof(m));
20 }
21 } maxtr;
22 int f[10000];
23 int fin(LL n);
24 LL quick(LL n,LL m,LL mod);
25 int main(void)
26 {
27 memset(prime,0,sizeof(prime));
28 int i,j;
29 for(i = 0; i <= 300; i++)
30 {
31 oula[i] = i;
32 }
33 int cn = 0;
34 for(i = 2; i <= 300; i++)
35 {
36 if(!prime[i])
37 {
38 ans[cn++] = i;
39 for(j = i; (i*j) <= 300; j++)
40 {
41 prime[i*j] = true;
42 }
43 }
44 }//printf("%d\n",cn);
45 for(i = 0; i < cn; i++)
46 {
47 for(j = 1; ans[i]*j <= 300; j++)
48 {
49 oula[ans[i]*j]/=ans[i];
50 oula[ans[i]*j]*=(ans[i] - 1);
51 }
52 }
53 ff[0] = 0;
54 ff[1] = 1;
55 for(i = 2; i <= 20; i++)
56 {
57 ff[i] = ff[i-1]+ff[i-2];
58 }
59 //printf("%d\n",ff[20]);
60 LL A,B,N,C;
61 int T;
62 scanf("%d",&T);
63 int __ca = 0;
64 while(T--)
65 {
66 scanf("%llu %llu %llu %llu",&A,&B,&N,&C);
67 {
68 printf("Case %d: ",++__ca);
69 if(C == 1)
70 printf("0\n");
71 else
72 {
73 int k = fin(C);
74 LL ask = quick(A,B,(LL)k);
75 LL c = (LL)f[ask];
76 if(c == 0)
77 printf("0\n");
78 else
79 {
80 LL v = A;
81 LL x = B;
82 int flag = 0;
83 {
84 int u = fin((LL)oula[C]);
85 LL avk = quick(A,B,(LL)u);
86 LL app = (LL)f[avk];
87 LL ni = quick(app,N-1,(LL)oula[C]);
88 ni = ni + (LL)oula[C];
89 printf("%llu\n",quick(c,ni,C));
90 }
91 }
92 }
93 }
94 }
95 return 0;
96 }
97 int fin(LL n)
98 {
99 f[0] = 0;
100 f[1] = 1;
101 int id;
102 int i;
103 for(i = 2; i < 5000; i++)
104 {
105 f[i] = f[i-1]+f[i-2];
106 f[i]%=n;
107 if(f[i] == f[1]&&f[0] == f[i-1])
108 {
109 id = i-2;
110 break;
111 }
112 }//printf("%d\n",id);
113 return id+1;
114 }
115 LL quick(LL n,LL m,LL mod)
116 {
117 LL ak = 1;
118 n%=mod;
119 while(m)
120 {
121 if(m&1)
122 {
123 ak = ak*n%mod;
124 }
125 n = n*n%mod;
126 m/=2;
127 }
128 return ak;
129 }

Interesting Fibonacci(hdu 2814)的更多相关文章

  1. hdu 2814 Interesting Fibonacci

    pid=2814">点击此处就可以传送 hdu 2814 题目大意:就是给你两个函数,一个是F(n) = F(n-1) + F(n-2), F(0) = 0, F(1) = 1; 还有 ...

  2. hdu Interesting Fibonacci

    Interesting Fibonacci Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  3. HDU 2814 斐波那契循环节 欧拉降幂

    一看就是欧拉降幂,问题是怎么求$fib(a^b)$,C给的那么小显然还是要找循环节.数据范围出的很那啥..unsigned long long注意用防爆的乘法 /** @Date : 2017-09- ...

  4. BestCoder10 1001 Revenge of Fibonacci(hdu 5018) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5018 题目意思:给出在 new Fibonacci 中最先的两个数 A 和 B(也就是f[1] = A ...

  5. (字典树)Revenge of Fibonacci -- HDU -- 4099

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=4099 要用c++交哦, G++ MLE 不是很懂,先粘上慢慢学习 代码: #include<std ...

  6. Hat's Fibonacci hdu 1250

    Problem Description A Fibonacci sequence is calculated by adding the previous two members the sequen ...

  7. hdu 2814 快速求欧拉函数

    /** 大意: 求[a,b] 之间 phi(a) + phi(a+1)...+ phi(b): 思路: 快速求欧拉函数 **/ #include <iostream> #include & ...

  8. HDU - 2814 Visible Trees

    题意: m*n(1<=m,n<=100000)的森林里,起始点在(1,1),某人从(0,0)点开始看,问能看到多少棵树. 题解: 求出1~x中的每个数与1~y的数中互质的数的总和.用素数筛 ...

  9. 【转载】ACM总结——dp专辑

    感谢博主——      http://blog.csdn.net/cc_again?viewmode=list       ----------  Accagain  2014年5月15日 动态规划一 ...

随机推荐

  1. 框架学习-MyBatis(01)

    1.MyBatis是持久层框架 什么是持久化: 狭义:把数据永久性的保存到数据当中 广义:针对于数据库的所有操作都称为持久化操作,CreateReadUpdateDelete操作 2.有哪些持久层框架 ...

  2. 《手把手教你》系列技巧篇(四十六)-java+ selenium自动化测试-web页面定位toast-下篇(详解教程)

    1.简介 终于经过宏哥的不懈努力,偶然发现了一个toast的web页面,所以直接就用这个页面来夯实一下,上一篇学过的知识-处理toast元素. 2.安居客 事先声明啊,宏哥没有收他们的广告费啊,纯粹是 ...

  3. Ubuntu16.04安装 2.8.5版本Ansible

    wget https://bootstrap.pypa.io/pip/2.7/get-pip.py && python get-pip.py pip install --upgrade ...

  4. flink04 -----1 kafkaSource 2. kafkaSource的偏移量的存储位置 3 将kafka中的数据写入redis中去 4 将kafka中的数据写入mysql中去

    1. kafkaSource 见官方文档 2. kafkaSource的偏移量的存储位置 默认存在kafka的特殊topic中,但也可以设置参数让其不存在kafka的特殊topic中   3   将k ...

  5. C++字节对齐(对象大小)

    内部数据成员对齐参考这篇 https://www.cnblogs.com/area-h-p/p/10316128.html 这里只强调C++字节对齐特点 ①静态数据成员属于类域,在对象中不占大小 ②若 ...

  6. Java 使用slf4j记录日志

    引入依赖 <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12< ...

  7. 图书管理系统总结——JAVA Swing控件简介

    断断续续学习JAVA语言,写了一个多月数据库大作业,终于在五一过后写完了.由于第一次使用JAVA和数据库,遇到了许多问题,记录下来,以备以后查看. 我使用的JAVA SE,说实话,在开发后期,觉得JA ...

  8. Android App加固原理与技术历程

    App为什么会被破解入侵 随着黑客技术的普及化平民化,App,这个承载我们移动数字工作和生活的重要工具,不仅是黑客眼中的肥肉,也获得更多网友的关注.百度一下"App破解"就有529 ...

  9. <转>企业应用架构 --- 分层

    系统架构师-基础到企业应用架构-分层[上篇] 一.前言 大家好,接近一年的时间没有怎么书写博客了,一方面是工作上比较忙,同时生活上也步入正轨,事情比较繁多,目前总算是趋于稳定,可以有时间来完善以前没有 ...

  10. tomcat架构分析及配置详解

    浏览器访问服务器的流程 请求发起的过程: 注意:浏览器访问服务器使用的是http协议,http是应用层协议,而具体传输还是使用的TCP/IP协议 Tomcat系统总架构 2.1 Tomcat请求处理过 ...