求助!!!最普通方法,60pts!!悬关

P1001 A+B Problem

pengguangze @ 2024-08-15 16:27:25

P1001

只使用了快速幂!!!!非常短!!!

记录详情

代码(在菜鸟上,不需要登录)


by microchip @ 2024-08-15 16:38:52

取模取 1e8 有问题,int类最大有2147483647比 1e8 大多了


by chrispang @ 2024-08-15 18:50:40

@pengguangze

#include<bits/stdc++.h>
using namespace std;
int qmi(int m, int k, int p) {
    int res = 1 % p, t = m;
    while (k) {
        if (k & 1) res = res * t % p;
        t = t * t % p;
        k >>= 1;
    }
    return res;
}
int main() {
    int a, b; scanf("%d%d", &a, &b);
    printf("%d", qmi(a, 1, INT_MAX) + qmi(b, 1, INT_MAX));
    return 0;
}

改成INT_MAX就可以了


by pengguangze @ 2024-08-16 14:31:15

@chrispang


by pengguangze @ 2024-08-16 14:31:55

@microchip 3克油,已关


by chengxi13205537253 @ 2024-08-16 16:05:56

#include <stdio.h>

int main()
{
    int a,b;
    scanf("%d%d",&a,&b);
    printf("%d\n", a+b);
    return 0;
}

by chengxi13205537253 @ 2024-08-16 16:06:36

s = input().split()
print(int(s[0]) + int(s[1]))

|