#include <iostream>
#include <string>
using namespace std;
string stringModuloWithoutLeadingZeros(const string& str, int n) {
long long result = 0;
// Oblicz string modulo int
for (char c : str) {
result = (result * 10 + (c - '0')) % n;
}
// Zamiana wyniku na string
string resultStr = to_string(result);
// Usunięcie zer wiodących
size_t nonZeroPos = resultStr.find_first_not_of('0');
if (nonZeroPos != string::npos) {
return resultStr.substr(nonZeroPos); // Zwracamy wynik bez zer wiodących
} else {
return "0"; // Jeśli wynik to 0
}
}
int main() {
string input;
int n;
cout << "Podaj string (liczbę): ";
cin >> input;
cout << "Podaj modulo: ";
cin >> n;
string result = stringModuloWithoutLeadingZeros(input, n);
cout << "Wynik: " << result << endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RyaW5nPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCnN0cmluZyBzdHJpbmdNb2R1bG9XaXRob3V0TGVhZGluZ1plcm9zKGNvbnN0IHN0cmluZyYgc3RyLCBpbnQgbikgewogICAgbG9uZyBsb25nIHJlc3VsdCA9IDA7CgogICAgLy8gT2JsaWN6IHN0cmluZyBtb2R1bG8gaW50CiAgICBmb3IgKGNoYXIgYyA6IHN0cikgewogICAgICAgIHJlc3VsdCA9IChyZXN1bHQgKiAxMCArIChjIC0gJzAnKSkgJSBuOwogICAgfQoKICAgIC8vIFphbWlhbmEgd3luaWt1IG5hIHN0cmluZwogICAgc3RyaW5nIHJlc3VsdFN0ciA9IHRvX3N0cmluZyhyZXN1bHQpOwoKICAgIC8vIFVzdW5pxJljaWUgemVyIHdpb2TEhWN5Y2gKICAgIHNpemVfdCBub25aZXJvUG9zID0gcmVzdWx0U3RyLmZpbmRfZmlyc3Rfbm90X29mKCcwJyk7CiAgICBpZiAobm9uWmVyb1BvcyAhPSBzdHJpbmc6Om5wb3MpIHsKICAgICAgICByZXR1cm4gcmVzdWx0U3RyLnN1YnN0cihub25aZXJvUG9zKTsgLy8gWndyYWNhbXkgd3luaWsgYmV6IHpl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