题意:

询问有多少数\(n\)满足\(n^{n!}\equiv b\mod p \land\ n\in[1,M]\),数据范围:\(M\leq2^{64}-1,p\leq1e5\)

思路:

这题显然要用欧拉降幂,\(n!\)小于\(\varphi(p)\)的直接暴力算,\(n!\neq 0\mod \varphi(p)\)也直接暴力。
\(n!\equiv 0\mod \varphi(p)\)显然这时质数恒为\(\varphi(p)\),由鸽笼定理得:
当\(x\)是常数时,\(1^x,2^x,\dots,n^x,\dots\mod p\)有循环节为\(\varphi(p)\)
那么直接按循环节搞一下即可。
注意一下,当\(b=0,M=2^{64}-1,p=1\)时,答案爆\(long long\)。

代码:

#include<map>
#include<set>
#include<queue>
#include<cmath>
#include<stack>
#include<ctime>
#include<vector>
#include<cstdio>
#include<string>
#include<cstring>
#include<sstream>
#include<iostream>
#include<algorithm>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
const int maxn = 1e5 + 5;
const int MAXM = 3e6;
const ll MOD = 998244353;
const ull seed = 131;
const int INF = 0x3f3f3f3f;
ull euler(ull n){ull res = n, a = n;for(int i = 2; i * i <= a; i++){if(a % i == 0){res = res / i * (i - 1);while(a % i == 0) a/= i;}}if(a > 1) res = res / a * (a - 1);return res;
}
ull ppow(ull a, ull b, ull mod){ull ret = 1;while(b){if(b & 1) ret = ret * a % mod;a = a * a % mod;b >>= 1;}return ret;
}
ull rec[maxn];
int main(){int T, ca = 1;scanf("%d", &T);while(T--){ull b, p, m;scanf("%I64u%I64u%I64u", &b, &p, &m);if(b == 0 && p == 1){if(m == 18446744073709551615ULL)printf("Case #%d: 18446744073709551616\n", ca++);elseprintf("Case #%d: %I64u\n", ca++, m + 1);continue;}ull phi = euler(p);ull ans = 0, fac = 1;ull i = 1;if(b == 0) ans++;for(i = 1; i <= m; i++){if(fac * i >= phi) break;fac = fac * i;if(ppow(i, fac, p) == b) ans++;}for(; i <= m; i++){if(fac * i % phi == 0) break;fac = fac * i % phi;if(ppow(i, fac + phi, p) == b) ans++;}if(i <= m){ull cnt = 0;for(int j = 1; j <= p; j++){rec[j] = ppow(j, phi, p);if(rec[j] == b) cnt++;}for(; i <= p && i <= m; i++){if(rec[i] == b) ans++;}if(i <= m){ull rest = m - p;ans += rest / p * cnt;rest -= rest / p * p;for(i = 1; i <= rest; i++){if(rec[i] == b) ans++;}}}printf("Case #%d: %I64u\n", ca++, ans);}return 0;
}

转载于:https://www.cnblogs.com/KirinSB/p/11536602.html

HDU 4335 What is N?(指数循环节)题解相关推荐

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

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

  2. FUZ 1759 Super A^B mod C (指数循环节/模板)

    题意:求A^B mod C,其中(1<=A,C<=1000000000,1<=B<=10^1000000). 思路: 在有些题目中我们需要对指数进行降幂处理才能计算.比如计算 ...

  3. 【HDU - 3746 】Cyclic Nacklace (KMP,最小循环节问题)

    题干: CC always becomes very depressed at the end of this month, he has checked his credit card yester ...

  4. hdu 3746 kmp求循环节 下标从1开始

    长度为m[1,2...m]的模式的循环节为 m-next[m] , aaa  循环节clc为1  (clc=m-next[m]= 3-2  =1)       此时   m%clc == 0   表示 ...

  5. HDU 3068 2017 Multi-University Training Contest - Team 1 1006 Fuction: 循环节+最后一步

    题意:给出一个0..n-1的全排列a,给出一个0..m-1的全排列b,现在要求计算函数F(定义域0..n-1 值域0..m-1)的个数,使得对所有的0..n-1的 i 都有 F(i)=b(F(ai)) ...

  6. 数论 + 公式 - HDU 4335 What is N?

    What is N? Problem's Link:  http://acm.hdu.edu.cn/showproblem.php?pid=4335 Mean: 给你三个数b.P.M,让你求有多少个n ...

  7. [代码]HDU 4335 What is N?

    Abstract HDU 4335 What is N? 数论 Body Source http://acm.hdu.edu.cn/showproblem.php?pid=4335 Descripti ...

  8. 循环节 - 【数论】

    循环节 引言: 小学的规律题大家不陌生吧,经常跟取余数挂钩的那种,其实挺简单的.比如给你一个序列1 3 5 7 9 1 3 5 7 9 1 3 -这就是小学题目嘛,对吧看着好简单. 循环节: 其实现在 ...

  9. 欧拉函数求一个数倒数的循环节长度

    首先,费马小定理a与p互素,则a^(p-1)≡1(mod p)  对于一个素数p,取a=10,那么10^(p-1)≡1(mod p)  如果找到一个正整数e使得10^e/p-1/p为整数,那么e就是1 ...

  10. 求循环小数的表示以及循环节长度

    问题:输入整数a和b,输出a/b的循环小数表示以及其循环节长度.例如 a=5 b=43 小数表示为0.(116279069767441860465),循环节长度为21 分析:模拟长除法的计算过程. ① ...

最新文章

  1. 《算法基础:打开算法之门》一1.5 拓展阅读
  2. STM32 驱动例程
  3. DATETIME类型和BIGINT 类型互相转换
  4. 51单片机c语言测距,求助 关于C51单片机超声波测距 C语言程序设计 高手帮帮忙...
  5. flux读取不到数据_spring-webflux两种开发模式,获取不到使用ajax的post提交的数据?...
  6. 35所大学获批新增「人工智能」本科专业,工学学位、四年制
  7. 问题 1073: 弟弟的作业
  8. C语言 字符串大小写转换
  9. mysql连接费时_连接mysql和 建索引花费
  10. 与context的关系_Go中的Context超时和关闭是如何实现的呢?
  11. 探寻 JavaScript 逻辑运算符(与、或)的真谛
  12. 使命召唤ol显示服务器超时,使命召唤ol网络延迟高的完整解决方案
  13. linux视频教程哪个最好_最好的Linux教程
  14. Android开发 入门篇(一)
  15. 弱电从业人员必须学习的一些CAD绘图技巧
  16. java 处理汉字枚举类_浅谈java枚举类(附代码)
  17. idea的英文是什么意思_intellij是什么意思
  18. 电子招投标技术的五大好处
  19. Hibernate5
  20. 7月第1周风控关注 微信支付SDK曝XXE漏洞 可伪造订单

热门文章

  1. 批量删除redis key
  2. 三数之和,去除重复。
  3. Excel中index和match函数的应用实例
  4. HDU-2161 Primes
  5. [org/springframework/jdbc/support/sql-error-codes.xml]
  6. 【个人笔记】rabbitMQ下Fanout与Topic两种模式同时用注意事项
  7. 工作3年,还不懂单点登录系统?看看这8幅漫画~
  8. 原创整理:92份面试题,累计3625页,肝的太累了!
  9. 红帽新 Logo 为何要移除黑影人?
  10. ​30 岁了,依然一事无成