hdu 3221 Brute-force Algorithm

Mac安装Weblogic教程 1.Weblogic的下载 这次安装的是最新版本12 官网下载地址: http://www.oracle.com/technetwork/middleware/weblogic/downloads/index.html 下载需要登录账号,如没有账号要注册一个 下载后的文件如下图,其中fmw_12.2.1.3.0_wls_quick.jar文件就是安装包了,注意现在不要对它进行解压 2.安装前的确... 阅读详情

Brute-force Algorithm

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


Problem Description
Professor Brute is not good at algorithm design. Once he was asked to solve a path finding problem. He worked on it for several days and finally came up with the following algorithm:

Any fool but Brute knows that the function “funny” will be called too many times. Brute wants to investigate the number of times the function will be called, but he is too lazy to do it.

Now your task is to calculate how many times the function “funny” will be called, for the given a, b and n. Because the answer may be too large, you should output the answer module by P.
 

Input
There are multiple test cases. The first line of the input contains an integer T, meaning the number of the test cases.

For each test cases, there are four integers a, b, P and n in a single line.
You can assume that 1≤n≤1000000000, 1≤P≤1000000, 0≤a, b<1000000.
 

Output
For each test case, output the answer with case number in a single line.
 

Sample Input
3 3 4 10 3 4 5 13 5 3 2 19 100
 

Sample Output
Case #1: 2 Case #2: 11 Case #3: 12
 

分析:见hdu4550
#include<cstdio>
#include<cmath>
#define ll __int64
ll a,b,p,n;
struct Matrix{
	ll v[2][2];
};
Matrix A={0,1,1,1},B={1,0,0,1};
ll euler(ll x){
	ll i,ans=x,t=(ll)sqrt(x*10.0);
	for(i=2;i<=t;i++)if(x%i==0){
		ans=ans/i*(i-1);
		while(x%i==0)x/=i;
	}
	if(x>1)ans=ans/x*(x-1);
	return ans;
}
ll quickpow(ll x,ll n){
	ll ans=1;
	while(n){
		if(n&1)ans=ans*x%p;
		n>>=1;
		x=x*x%p;
	}
	return ans;
}
Matrix mul(Matrix m1,Matrix m2,ll M){
	int i,j,k;
	Matrix c;
	for(i=0;i<2;i++)for(j=0;j<2;j++){
		c.v[i][j]=0;
		for(k=0;k<2;k++)c.v[i][j]+=(m1.v[i][k]*m2.v[k][j])%M;
		c.v[i][j]%=M;
	}
	return c;
}
Matrix Mpow(int n,ll M){
	Matrix x=A,c=B;
	while(n>=1){
		if(n&1)c=mul(c,x,M);
		n>>=1;
		x=mul(x,x,M);
	}
	return c;
}
int main(){
	int T,ca=1,i;
	scanf("%d",&T);
	while(T--){
		scanf("%I64d%I64d%I64d%I64d",&a,&b,&p,&n);
		printf("Case #%d: ",ca++);
		if(n==1){printf("%I64d\n",a%p);continue;}
		if(n==2){printf("%I64d\n",b%p);continue;}
		if(n==3){printf("%I64d\n",((a%p)*(b%p))%p);continue;}
		ll phi=euler(p),f1=0,f2=1,f3,aa,bb;bool j=0;
		for(i=4;i<=n;i++){
			f3=f1+f2;
			if(f3>=phi){f3%=phi;j=1;break;}
			f1=f2,f2=f3;
		}
		if(j){
			Matrix res=Mpow(n-3,phi);
			f1=res.v[1][0],f2=res.v[1][1],f3=f1+f2;
			aa=f2%phi+phi,bb=f3%phi+phi;
		}
		else {aa=f3,bb=f1+f2;}
		printf("%I64d\n",(quickpow(a,aa)*quickpow(b,bb))%p);
	}
	return 0;
}


AltiumDesigner 09安装过程破解问题 . 首先分享一下破解文件,网上总是下载不到,好不容易下载到了,放在网盘上,有需要的自取。AltiumDesigner 09破解文件。链接:https://pan.baidu.com/s/1ZGvbR_6T51hpcaFbQiMX5w 密码:qwvaAltiumDesigner 09安装安装文件,比较大,包含破解文件:链接:https://pan.baidu.com/s/1mfgragB519jpGfR... 阅读详情

相关推荐

STM32F407+LAN8720网口不通?别慌,手把手教你用CubeMX和LWIP搞定RMII以太网(附复位与PHY地址避坑指南)

本文详细解析了STM32F407与LAN8720通过RMII接口实现以太网通信的完整流程,重点解决了网口不通的常见问题。从硬件连接到CubeMX配置,再到LWIP网络参数设置,提供了复位时序、PHY地址配置等关键细节的避坑指南,帮助开发者快速排查和解决以太网通信故障。

weixin_33695082的博客 419

HDU 3221 Brute-force Algorithm(指数降幂公式)

题目链接; HDU 3221 Brute-force Algorithm 题意: 根据递归可以得到f[1]=a,f[2]=b,f[n]=f[n−1]∗f[n−2](n≥3)f[1]=a, f[2]=b,f[n]=f[n-1]*f[n-2](n\geq 3),给出a,b,p,na,b,p,n求f[n]%p的值。f[n]\% p的值。 数据范围:1≤n≤1000000000,1≤P≤100000

ramay7 1539

用电脑通过网口控制keysight示波器

Keysight HD304MSO示波器提供1GHz带宽、14位高精度ADC及10.1英寸触控屏,支持50μV低噪声信号捕获和1.3M波形/秒刷新率。配备4通道探头、逻辑分析仪接口及100Mpts存储深度,含故障诊断、FFT等高级功能。通过网线连接电脑安装TightVNC软件(示波器IP为169.254.163.24)可实现远程控制,相比U盘传输更高效。(149字)

johnboat的专栏 1135

HDU3221Brute-force Algorithm(矩阵快速幂&&指数降幂)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3221

追梦赤子心 1169

Silvaco Atlas新手入门:从安装到第一个半导体器件仿真(附DeckBuild配置)

本文为Silvaco Atlas新手提供了一份从软件安装、DeckBuild环境配置到完成第一个半导体器件仿真的实战指南。通过构建一个经典的PN结二极管案例,详细讲解了Atlas仿真语句的语法、核心命令顺序以及结果调试与可视化方法,帮助初学者快速上手并理解TCAD仿真流程。

sql99的博客 332

Python+Selenium实战:5分钟搞定快手评论区数据采集(附完整代码)

本文详细介绍了如何使用Python和Selenium快速采集快手评论区数据,提供完整的代码实现和优化方案。通过动态加载处理和智能等待策略,5分钟内即可构建高效的评论采集工具,适用于用户行为分析和内容挖掘等场景。

weixin_30415113的博客 342

hdu 3221 (指数循环节)

x^k=x^(k%phi(p)+phi(p))%p( k>=phi(p))  #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace

BryantMark 638

宏基因组分析|完整分析流程梳理

今天先从最基础的全流程框架说起,无论是刚接触的萌新,还是想查漏补缺的同行,都能找到有用的信息。

weixin_70911870的博客 3164

HDU 3221矩阵快速幂&欧拉定理

#include &lt;bits/stdc++.h&gt; #define ll long long using namespace std; const int N = 2; const int MX = 40000; ll a, b, p, MOD, n, tot, prime[7000]; bool nop[MX]; struct Matrix { ll mat[N][N];...

ACM2017 528

Springboot项目中使用邮箱验证码注册登录的代码实现

本文介绍了在Spring Boot应用中实现邮箱验证码注册和登录功能的完整方案。文章首先概述了三种用户认证方式(邮箱验证码注册/登录和传统密码登录),然后详细说明了实现所需的技术栈(Spring Boot、Spring Security、JWT等)。重点阐述了邮件服务配置、验证码生成与存储的核心实现,包括QQ邮箱授权码获取、Thymeleaf邮件模板处理以及验证码缓存管理。最后展示了发送验证码和用户注册的API实现,为开发者提供了完整的参考方案。该方案兼顾安全性和用户体验,适合现代Web应用的用户认证需求。

BXCQ_xuan的技术专栏 | 实战干货·实践教程·学习笔记 1339

sim800c插卡后指示灯还是一秒一闪无法接收发送短信,如何解决?

🏆 本文收录于《全栈Bug调优(实战版)》专栏,致力于分享我在项目实战过程中遇到的各类Bug及其原因,并提供切实有效的解决方案。无论你是初学者还是经验丰富的开发者,本文将为你指引出一条更高效的Bug修复之路,助你早日登顶,迈向财富自由的梦想🚀!同时,欢迎大家关注、收藏、订阅本专栏,更多精彩内容正在持续更新中。让我们一起进步,Up!Up!Up!    备注: 部分问题/难题源自互联网,经过精心筛选和整理,结合数位十多年大厂实战经验资深大佬经验总结所得,数条可行方案供所需之人参考。

**My Coding Family** 1167

hdu3221 Brute-force Algorithm矩阵快速幂&&a^b%p=a^(b%phi(p)+phi(p))%p b>=phi(p)

Brute-force Algorithm Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1530    Accepted Submission(s): 379 Problem Description Professor

Shirley 3150

Chrome DevTools MCP 实战完整教程

本教程介绍了Chrome DevTools MCP(Model Context Protocol)在智能Web测试中的应用。该系统通过MCP协议将Chrome开发者工具能力标准化,并与AI结合,提供了统一的测试解决方案。核心功能包括智能自动化、深度调试分析和性能监控优化。教程详细讲解了环境搭建、MCP服务器配置、参数说明及多种工具集(输入自动化、导航、设备仿真、性能分析等)的使用方法。通过mcp-use库的MCPAgent和MCPClient组件,用户可以轻松实现自然语言驱动的浏览器操作和测试流程管理。

blues_C的博客 3803

HDU 3221 Brute-force Algorithm

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3221 思路: 稍微开个脑洞想想,就能发现递推式是f(n)=f(n-1)*f(n-2),再想想就能想到可通过先计算a用了多少次,b用了多少次来计算,最后套一个快速幂来计算f(n),在计算a用了多少次的时候又可以发现,a的次数其实是一个斐波那契数,但是在计算a的次数的时候会发现这个次数会爆long l

乐观之奋斗者 554

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

HDU 3221 Brute-force Algorithm【矩阵快速幂】【欧拉降幂】

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3221 AC代码: #include<bits/stdc++.h> using namespace std; typedef long long ll; const int mod=10000; ll n,p,aa,b; const ll maxn=1e6+10; ll phi[maxn];...

weixin_43499182的博客 352

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

HDU 3221 Brute-force Algorithm

Description Professor Brute is not good at algorithm design. Once he was asked to solve a path finding problem. He worked on it for several days and finally came up with the following algorithm: 

Occult 436

HDU 3221Brute-force Algorithm(降幂公式 神似hdu4549)

Brute-force Algorithm Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1940    Accepted Submission(s): 475 Problem Description Profe

布生气 1944

Brute-force Algorithm [HDU 3221]

http://acm.hdu.edu.cn/showproblem.php?pid=3221 对于指数取欧拉函数需要注意一下,a^x%P=a^(x%phi(P)+phi(P))%P View Code //A^x = A^(x % Phi(C) + Phi(C)) (mod C) 的应用 const int MM = 1111111; #define debug puts("wro...

weixin_30919571的博客 153
上一篇: 金山西山居初赛第二场
下一篇: 金山西山居初赛第三场
libing923
博客等级 码龄15年 12粉丝 71原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值