//做这种题我知道了,以后数字能定多大就定多大,最后就long long int,前面都是把数字定义为int,老是WA
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
using namespace std;
int main()
{
string str1,str2,str3;
while(cin>>str1>>str2>>str3)
{
unsigned long int p = 0;
unsigned long int n;
char op = str2[0];
istringstream(str3)>>n;
for(int i = 0 ,len = str1.length(); i < len ;++i )
{
unsigned long int temp = p*10+ str1[i]-'0' ;
p = temp%n;
str1[i] = temp/n;
}
if(op == '/')
{
transform(str1.begin(),str1.end() , str1.begin() , bind1st(plus<int>(),48));
int pos = str1.find_first_not_of('0');
if(pos == string::npos) cout<<"0"<<endl;
else
cout<<str1.substr(pos)<<endl;
}
else if(op == '%')
{
cout<<p<<endl;
}
}
return 0;
}