世界!我有个问题。今天我尝试创建一个代码,它可以找到加泰罗尼亚语号码。但在我的程序中可以是长数字。我找到了分子和分母。但我不能 div 长数字!此外,该程序中只能使用标准库。请帮帮我。这是我的代码
#include <vector>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
const int base = 1000*1000*1000;
vector <int> a, b;
int n, carry = 0;
cin>>n;
a.push_back(n);
for (int ii=n+2; ii!=(2*n)+1;++ii) {
carry = 0;
for (size_t i=0; i<a.size() || carry; ++i) {
if (i == a.size())
a.push_back (0);
long long cur = carry + a[i] * 1ll * ii;
a[i] = int (cur % base);
carry = int (cur / base);
}
}
while (a.size() > 1 && a.back() == 0) a.pop_back();
b.push_back(n);
for (int ii=1; ii!=n+1;++ii) {
carry = 0;
for (size_t i=0; i<b.size() || carry; ++i) {
if (i == b.size())
b.push_back (0);
long long cur = carry + b[i] * 1ll * ii;
b[i] = int (cur % base);
carry = int (cur / base);
}
}
while (b.size() > 1 && b.back() == 0) b.pop_back();
cout<<(a.empty() ? 0 : a.back());
for (int i=(int)a.size()-2; i>=0; --i) cout<<(a[i]);
cout<<" ";
cout<<(b.empty() ? 0 : b.back());
for (int i=(int)b.size()-2; i>=0; --i) cout<<(b[i]);
//system("PAUSE");
cout<<endl;
return 0;
}
PS对不起我的英语不好=)