Submission

Status:

PPPPPPPPPP

Subtask/Task Score:

100/100

Score: 100

User: Kei

Problemset: เลขหลักของผลคูณ

Language: cpp

Time: 0.004 second

Submitted On: 2026-10-07 14:46:14

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>; 

string inf_add(string a, string b){
    int thea,theb,theadd,carry=0;
    if(a.size()>b.size()) b=string(a.size()-b.size(),'0')+b;
    else if(b.size()>a.size()) a=string(b.size()-a.size(),'0')+a;
    string c(a.size()+1,'0');
    for(int i=a.size()-1;i>=0;i--){
        thea = a[i]-'0';
        theb = b[i]-'0';
        theadd = thea+theb+carry;
        c[i+1]=theadd%10+'0';
        carry=theadd/10;
    }
    if(carry!=0)c[0] = char(carry+'0');   
    int p=0;
    while(p+1<(int)c.size() && c[p]=='0')p++;
    return c.substr(p);
}

string inf_mult(string a, string b){
    if(a == "0" || b == "0") return "0";

    int thea,theb,themult,carry;
    string c="";
    for(int i=b.size()-1;i>=0;i--){
        carry=0;
        string themultstr(a.size(),'0');
        theb=b[i]-'0';
        for(int j=a.size()-1;j>=0;j--){
            thea=a[j]-'0';
            themult = thea*theb+carry;
            themultstr[j]=themult%10+'0';
            carry=themult/10;
        }
        if(carry!=0) themultstr=char(carry+'0')+themultstr;
        c=inf_add(c,themultstr+string(b.size()-i-1,'0'));
    }
    return c;
}

void solve(){
    string a,b;
    int x;
    cin >> a >> b >> x;
    string c = inf_mult(a,b);
    if(x>0 && x<=(int)c.size() ? cout<<c[x-1] : cout<<'_');
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
    return 0;
}