跳到正文

题解

题解:P10414 [蓝桥杯 2023 国 A] 2023 次方

ybw0731约 6 分钟
原文
文章信息与版本

文章信息

发布
2025年10月5日
收录
2025年12月12日
更新
2026年11月21日
篇幅
约 6 分钟
获赞
1
题目
P10414

版本

  1. v2当前
  2. v1

题目传送门

Part 1 题意

  • 求 2345...2023(mod2023)\Large2^{3^{4^{5^{...^{2023}}}}} \pmod {2023} 的值。

Part 1.5 代码

  • 懒人们直接输出 869869 即可。

Part 2 高斯降幂

  • 若 xy+1≡x(modp)x ^ {y+1} \equiv x \pmod p,则 xya+b≡xb(modp)x^{ya+b} \equiv x^b \pmod p。

  • 证明:xya+b=(xy+1)a⋅xb−a≡xa⋅xb−a=xb(modp)x^{ya+b} =(x^{y+1})^a \cdot x^{b-a} \equiv x^a \cdot x^{b-a} = x^b \pmod p。

Part 3 降幂×\times1

  • 所以我们就可以进行以下操作:
2345...2023≡2345...2023(modx)\Large2^{3^{4^{5^{...^{2023}}}}} \equiv \Large2^{3^{4^{5^{...^{2023}}}} \pmod x}
  • 其中 xx 满足 2x+1≡2(mod2023)2^{x+1} \equiv 2 \pmod {2023}。只需要写一个代码算算即可。
C++
#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int read(){
	int f=1,x=0;
	char s=getchar();
	while(s<'0'||s>'9'){
		if(s=='-') f=-1;
		s=getchar();
	}
	while(s>='0'&&s<='9'){
		x=(x<<1)+(x<<3)+(s^48);
		s=getchar();
	}
	return x*f;
}

signed main(){
	int sum=1;
	for(int i=1;i<=2023;i++){
		sum<<=1;
		sum%=2023;
		if(sum==2&&i!=1){
			cout<<i-1<<endl;
			return 0;
		}
	}
	return 0;
}
  • 输出 408408,所以我们只需要计算 345...2023(mod408)\Large3^{4^{5^{...^{2023}}}} \pmod {408} 的值即可。

Part 4 降幂×\times2

  • 同样的方法,我们又可以进行以下操作:
3456...2023≡3456...2023(mody)\Large3^{4^{5^{6^{...^{2023}}}}} \equiv \Large3^{4^{5^{6^{...^{2023}}}}\pmod y}
  • 其中 yy 满足 3y+1≡3(mod408)3^{y+1} \equiv 3\pmod {408},再写个代码算算。
C++
#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int read(){
	int f=1,x=0;
	char s=getchar();
	while(s<'0'||s>'9'){
		if(s=='-') f=-1;
		s=getchar();
	}
	while(s>='0'&&s<='9'){
		x=(x<<1)+(x<<3)+(s^48);
		s=getchar();
	}
	return x*f;
}

signed main(){
	int sum=1;
	for(int i=1;i<=408;i++){
		sum*=3;
		sum%=408;
		if(sum==3&&i!=1){
			cout<<i-1<<endl;
			return 0;
		}
	}
	return 0;
}
  • 输出 1616,所以我们只需要计算 456...2023(mod16)\Large4^{5^{6^{...^{2023}}}} \pmod {16} 的值即可。

  • 可由于 567...2023\Large5^{6^{7^{...^{2023}}}} 的值大于 22,所以 456...2023≡0(mod16)\Large4^{5^{6^{...^{2023}}}} \equiv0 \pmod {16}

  • 所以345...2023≡316(mod408)\Large3^{4^{5^{...^{2023}}}} \equiv 3^{16} \pmod {408}。

  • 只需要再求一下即可。

C++
#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int read(){
	int f=1,x=0;
	char s=getchar();
	while(s<'0'||s>'9'){
		if(s=='-') f=-1;
		s=getchar();
	}
	while(s>='0'&&s<='9'){
		x=(x<<1)+(x<<3)+(s^48);
		s=getchar();
	}
	return x*f;
}

signed main(){
	int sum=1;
	for(int i=1;i<=16;i++){
		sum*=3;
		sum%=408;
	}
	cout<<sum;
	return 0;
}
  • 输出 273273。

Part 5 计算答案

  • 最后求 2273mod  20232^{273} \mod 2023。
C++
#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int read(){
	int f=1,x=0;
	char s=getchar();
	while(s<'0'||s>'9'){
		if(s=='-') f=-1;
		s=getchar();
	}
	while(s>='0'&&s<='9'){
		x=(x<<1)+(x<<3)+(s^48);
		s=getchar();
	}
	return x*f;
}

signed main(){
	int sum=1;
	for(int i=1;i<=273;i++){
		sum<<=1;
		sum%=2023;
	}
	cout<<sum;
	return 0;
}
  • 最后输出 869869,终于可以输出了。

Part 6 结尾

  • 复制\textcolor{#52c41a}{复制}一时爽。
  • 棕名\textcolor{#ad8b00}{棕名}两行泪。

AC 链接

原文