b430. 簡單乘法 - 高中生程式解題系統

本文最後更新於:2024年1月12日 下午

Zerojudge
解題紀錄

b430. 簡單乘法 - 高中生程式解題系統

Zerojudge-b430.cpp

// Author : ysh
// 03/22/2022 Tue  9:18:35.58
#include<bits/stdc++.h>
using namespace std;
#define int long long
int check(int,int,int);
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int a;
    while(cin>>a) {
        int n;cin>>n;
        int p;cin>>p;
        cout<<check(a,n,p) % p<<"\n";
    }
    return 0;
}
int check(int a,int b,int c) {
    if(b == 0) return 0;
    int now = check(a,b >> 1,c);
    if(b & 1) return (a + (now + now) % c) % c;
    else return (now + now % c) % c;
}

b430. 簡單乘法 - 高中生程式解題系統
http://mysh212.github.io/algosolution/Zerojudge-b430.cpp/
作者
ysh
發布於
2022年3月22日
更新於
2024年1月12日
許可協議