首页
DreamJudge
院校信息
考研初试
考研复试
保研专区
讨论区
兑换中心
登录
注册
上岸
以下题解仅供学习参考使用。
抄袭、复制题解,以达到刷AC率/AC数量或其他目的的行为,在N诺是严格禁止的。
N诺非常重视学术诚信。此类行为将会导致您成为作弊者。具体细则请查看N诺社区规则。
799
2024年3月8日 17:45
幂次方 题解:
P1017
回复 0
|
赞 1
|
浏览 1.3k
#include<bits/stdc++.h> using namespace std; #define M 233333 typedef long long ll; ll gow(ll a, ll b, ll mod) { //同模取余:(a*b)%c = (a%c * b%c)%c ll res=1; while(b) {//一直循环到b次 if(b&1) res=res*a...
cideyitanjiu
2024年2月29日 20:20
幂次方 题解:
P1017
回复 0
|
赞 6
|
浏览 1.8k
//快速幂 //一、递归求解 // 1、经典递归,时间复杂度为O(Nlogn) #include<stdio.h> alg(long long X,long long N){ // 1 的 0 次方为 1 if(N == 0){ return 1; } return (alg(X,N - 1) * X); } int main(){ &...
carrot_huan
2024年1月16日 21:03
幂次方 题解:实在找不到哪里不对,向各位佬求助了
P1017
回复 2
|
赞 0
|
浏览 1.7k
#include<stdio.h> long long int Recusion(long long int x, long long int n) { long long int temp; if (n == 1) return x; else if(n==0) return 1 ; else if (n % 2 == 0) { &...
孙某人
2024年1月4日 17:06
幂次方 题解:
P1017
回复 0
|
赞 0
|
浏览 1.4k
//快速幂算法 //233333 #include <iostream> using namespace std; int main(){ long long a,b,sum=1; cin >> a >>b;//这里相当于a^b while(b)// 以3^10为例 10%2=0--->3^10=(9)^5 --->5%2==1 --->3^2*(81)^2--->...
930254841
2022年7月2日 20:39
经典快速幂(注意数据类型)
P1017
回复 0
|
赞 4
|
浏览 6.2k
#include <bits/stdc++.h> using namespace std; int quickPow(long long x, int n) { int res = 1; while (n >= 1) { if (n & 1 == 1) { res = res * x % 233333; } n >>= 1; x = (x % 233333) * (x % 233333); ...
James
2021年1月29日 20:29
快速幂模运算模板
P1017
回复 0
|
赞 2
|
浏览 11.4k
#include<iostream> using namespace std; #define ll long long //快速幂 /* 例如a^7 7=111=2^2*1+2^1*1+2^0*1=4+2+1 a^7=a^4*a^2*a^1 每次指数位置>>右移一位相当于指数位置除以2 对应于底数变成平方 a->a...
hijack
2020年6月24日 20:02
快速幂
P1017
回复 0
|
赞 5
|
浏览 14.6k
本题对于没有接触过快速幂算法的人来说应该是有很大难度,因为题目要求时间复杂度O(logn),不能使用暴力循环。 要解决本题必须要了解求幂取模运算的法则,比如本题涉及的 (a*b) % p = (a%p * b%p) %p;这是解决本题的核心。下边先上代码: #include <iostream> using namespace std; #define LL long long //位运算快速幂 LL fastPower(LL base, LL power, int p)//p为对谁求余 { LL res =...
Ang
2020年3月12日 00:50
快速幂签到题
P1017
回复 0
|
赞 1
|
浏览 11.8k
#include<bits/stdc++.h> using namespace std; int main(){ long long x,n; cin>>x>>n; long long ans=1; while(n!=0){ if(n%2==1){ ans *= x; ans %= 233333; } n /= 2; x *= x; x %= 233333; ...
张祺源
2020年2月16日 14:34
我觉得唯一要注意的就是X和N的数据类型
P1017
回复 0
|
赞 6
|
浏览 14.6k
#include<stdio.h> int main() { long long X,N,sum=1; scanf("%lld %lld",&X,&N); while(N>0) { if(N%2==1) { &n...
A1120161820
2020年3月20日 11:06
幂次方(c++)
P1017
回复 0
|
赞 2
|
浏览 13.8k
注意x和n的数据类型 #include<iostream> using namespace std; const int M = 233333; int main() { long long x, n; long long ans = 1; cin >> x >> n; x %= M; while (n > 0) { if (n%2 == 1) ans = (ans*x) % M; n /= 2; x = (x*x) % M; } cout << ans <...
1
2
3
题目
幂次方
题解数量
30
发布题解
在线答疑
热门题解
1
1017 幂次方 快速幂模板
2
幂次方 题解:数据类型统一longlong
3
幂次方 题解:
4
幂次方 题解:
5
幂次方 题解:运用二分快速幂思想和同余模定理即可。
6
幂次方 题解:
7
幂次方 题解:二进制快速幂原理
8
幂次方 题解:暴力至高
9
幂次方 题解:
10
幂次方 题解:我是范小勤,我不会