凤兮之夜 @ 2022-10-27 20:59:01
#include <iostream>
using namespace std;
int p;
int len;
int a[1000005];
int main() {
cin >> p;
a[0] = 1;
for (int i = 1; i <= p; i++) {
for (int j = 0; j <= len; j++)
a[j] *= 2;
for (int j = 0; j <= len; j++) {
if (a[j] >= 10) {
a[j + 1] += a[j] / 10;
a[j] %= 10;
}
if (a[len + 1])
len++;
}
}
a[0]--;
cout << len + 1 << endl;
for (int i = 499; i >= 0; i--)
cout << a[i];
return 0;
}
by 凤兮之夜 @ 2022-10-27 20:59:40
超时的问题晓得,第四题也没想着那全分┭┮﹏┭┮
by 杨建韬 @ 2022-10-27 21:05:17
快,速,幂,懂?
不懂请转移至这里:P1226快速幂模板
by Xy_top @ 2022-10-27 21:13:25
@凤兮之夜 你这个len不是这样求的,这样求的话万一溢出你就输出1000000了,
by Xy_top @ 2022-10-27 21:13:56
@凤兮之夜 应该要用换底公式(因为没有部分数据,所以这个可以卡成0分)
by Xy_top @ 2022-10-27 21:16:26
但是你这个好像也不会超欸
by 凤兮之夜 @ 2022-10-27 21:43:59
@stdios 但是五个TLE五个WE啊
by 凤兮之夜 @ 2022-10-27 21:46:08
@杨建韬
那要不顺便帮把1226也看一下吧┭┮﹏┭┮
对了3个点
#include <iostream>
using namespace std;
long long a, b, p, s;
long long quickPower() {
int base = a;
int ans = 1;
while (b > 0) {
if (b & 1 ) {
ans *= base;
ans %= p;
}
base *= base;
base %= p;
b >>= 1;
}
return ans % p;
}
int main() {
cin >> a >> b >> p;
int b1 = b;
long long ans = quickPower();
cout << a << "^" << b1 << " mod " << p << "=" << ans;
return 0;
}
by Xy_top @ 2022-10-27 21:53:01
@凤兮之夜 ans 开longlong,不然两个int相乘爆int
by Xy_top @ 2022-10-27 21:53:18
还有base
by 杨建韬 @ 2022-10-27 22:18:49
(笑死)不开longlong,