二次联通门 : codevs 2803 爱丽丝·玛格特罗依德

/*
codevs 2803 爱丽丝·玛格特罗伊德

   高精 + 找规律 显然, 能拆3就多拆3
不能拆就拆2 注意特判一下 */
#include <iostream>
#include <cstdio>
#include <vector>
#include <iomanip>
#include <cassert>
#include <algorithm> #define int64 long long using namespace std; #define Max 105 const int B = ;
const int L = ; inline int intcmp(int a, int b)
{
if (a > b)
return ;
else if (a < b)
return -;
else
return ;
} void read (int &now)
{
now = ;
register char word = getchar ();
while (word < '' || word > '')
word = getchar ();
while (word >= '' && word <= '')
{
now = now * + word - '';
word = getchar ();
}
}
struct BigInt
{ vector<int> a;
BigInt(){}
BigInt(int n)
{
while (n > )
a.push_back(n % B), n /= B;
} BigInt(int64 n)
{
while (n > )
a.push_back(n % B), n /= B;
}
inline void clr0()
{
while (!a.empty() && a.back() == )
a.pop_back();
}
inline BigInt &operator+=(const BigInt &rhs)
{
a.resize(max(a.size(), rhs.a.size()));
int t = ;
for (int i = ; i < (int)rhs.a.size(); i++)
{
a[i] += rhs.a[i] + t;
t = a[i] >= B;
a[i] -= B & (-t);
}
for (int i = (int)rhs.a.size(); t != && i < (int)a.size(); i++)
{
a[i] += t;
t = a[i] >= B;
a[i] -= B & (-t);
}
if (t != )
a.push_back(t);
return *this;
}
inline BigInt &operator-=(const BigInt &rhs)
{
a.resize(max(a.size(), rhs.a.size()));
int t = ;
for (int i = ; i < (int)rhs.a.size(); i++)
{
a[i] -= rhs.a[i] + t;
t = a[i] < ;
a[i] += B & (-t);
}
for (int i = (int)rhs.a.size(); t != && i < (int)a.size(); i++)
{
a[i] -= t;
t = a[i] < ;
a[i] += B & (-t);
}
clr0();
return *this;
}
inline BigInt &operator*=(const BigInt &rhs)
{
int na = (int)a.size();
a.resize(na + rhs.a.size());
for (int i = na - ; i >= ; i--)
{
int ai = a[i];
int64 t = ;
a[i] = ;
for (int j = ; j < (int)rhs.a.size(); j++)
{
t += a[i + j] + (int64)ai * rhs.a[j];
a[i + j] = t % B;
t /= B;
}
for (int j = (int)rhs.a.size(); t != && i + j < (int)a.size(); j++)
{
t += a[i + j];
a[i + j] = t % B;
t /= B;
}
assert(t == );
}
clr0();
return *this;
}
inline BigInt &operator/=(const BigInt &rhs)
{
return *this = div(rhs);
}
inline BigInt &operator%=(const BigInt &rhs)
{
return div(rhs), *this;
}
inline BigInt &shlb(int l = )
{
if (a.empty())
return *this;
a.resize(a.size() + l);
for (int i = (int)a.size() - ; i >= l; i--)
a[i] = a[i - l];
for (int i = ; i < l; i++)
a[i] = ;
return *this;
}
inline BigInt &shrb(int l = )
{
for (int i = ; i < (int)a.size() - l; i++)
a[i] = a[i + l];
a.resize(max((int)a.size() - l, ));
return *this;
}
inline int cmp(const BigInt &rhs) const
{
if (a.size() != rhs.a.size())
return intcmp(a.size(), rhs.a.size());
for (int i = (int)a.size() - ; i >= ; i--)
if (a[i] != rhs.a[i])
return intcmp(a[i], rhs.a[i]);
return ;
}
inline BigInt div(const BigInt &rhs)
{
assert(!rhs.a.empty());
if (rhs > *this)
return ;
BigInt q, r;
q.a.resize((int)a.size() - (int)rhs.a.size() + );
for (int i = (int)a.size() - ; i > (int)a.size() - (int)rhs.a.size(); i--)
{
r.shlb();
r += a[i];
}
for (int i = (int)a.size() - (int)rhs.a.size(); i >= ; i--)
{
r.shlb();
r += a[i];
if (r.cmp(rhs) < )
q.a[i] = ;
else
{
int le = , ri = B;
while (le != ri)
{
int mi = (le + ri) / ;
if ((rhs * mi).cmp(r) <= )
le = mi + ;
else
ri = mi;
}
q.a[i] = le - ;
r -= rhs * q.a[i];
}
}
q.clr0();
*this = r;
return q;
}
friend inline BigInt operator+(const BigInt &lhs, const BigInt &rhs)
{
BigInt res = lhs;
return res += rhs;
}
friend inline BigInt operator-(const BigInt &lhs, const BigInt &rhs)
{
BigInt res = lhs;
return res -= rhs;
}
friend inline BigInt operator*(const BigInt &lhs, const BigInt &rhs)
{
BigInt res = lhs;
return res *= rhs;
}
friend inline BigInt operator/(const BigInt &lhs, const BigInt &rhs)
{
BigInt res = lhs;
return res.div(rhs);
}
friend inline BigInt operator%(const BigInt &lhs, const BigInt &rhs)
{
BigInt res = lhs;
return res.div(rhs), res;
}
friend inline ostream &operator<<(ostream &out, const BigInt &rhs)
{
if (rhs.a.size() == )
out << "";
else
{
out << rhs.a.back();
for (int i = (int)rhs.a.size() - ; i >= ; i--)
out << setfill('') << setw(L) << rhs.a[i];
}
return out;
}
friend inline bool operator<(const BigInt &lhs, const BigInt &rhs)
{
return lhs.cmp(rhs) < ;
}
friend inline bool operator<=(const BigInt &lhs, const BigInt &rhs)
{
return lhs.cmp(rhs) <= ;
}
friend inline bool operator>(const BigInt &lhs, const BigInt &rhs)
{
return lhs.cmp(rhs) > ;
}
friend inline bool operator>=(const BigInt &lhs, const BigInt &rhs)
{
return lhs.cmp(rhs) >= ;
}
friend inline bool operator==(const BigInt &lhs, const BigInt &rhs)
{
return lhs.cmp(rhs) == ;
}
friend inline bool operator!=(const BigInt &lhs, const BigInt &rhs)
{
return lhs.cmp(rhs) != ;
}
}; int N;
BigInt Answer = ; int main (int argc, char *argv[])
{ for (read (N); N; )
{
if (N == )
{
N -= ;
Answer *= ;
}
else if (N >= )
{
N -= ;
Answer *= ;
}
else if (N == )
{
N -= ;
Answer *= ;
}
else if (N == )
{
puts ("");
return ;
}
}
cout << Answer;
return ;
}

最新文章

  1. [moka同学转载]Yii2 中国省市区三级联动
  2. css小技巧
  3. Fiddler Tips
  4. SelectedRows.CurrentRowSelected 和 DeleteItem
  5. WEB-INF目录与META-INF目录的作用
  6. 在Mvc中创建WebApi是所遇到的问题
  7. R语言的数据结构
  8. 【Python网络编程】多线程聊天软件程序
  9. Android 实现蘑菇街购物车动画效果
  10. ios 实现在tableViewCell上面添加长按手势 删除该条cell以及列表后台数据等
  11. 浅谈服务间通信【MQ在分布式系统中的使用场景】
  12. [Swift]LeetCode188. 买卖股票的最佳时机 IV | Best Time to Buy and Sell Stock IV
  13. Bootstrap如何配合字体自适应
  14. [转] Node.js中package.json中库的版本号详解(^和~区别)
  15. win10 安装 open live write
  16. hadoop管理
  17. Linux软件源书写格式解析及本地yum源制作
  18. python使用外部PY文件的变量
  19. kubernetes1.9管中窥豹-CRD概念、使用场景及实例
  20. CF 987 D. Fair

热门文章

  1. SQLServer作业调用链接服务器失败解决办法
  2. 解决Linq Join Group by 时报错:Nullable object must have a value.
  3. Dubbo(三):框架设计
  4. web和网络基础
  5. 英语orientaljasper鸡血石orientaljasper单词
  6. 汽车制造商表态:必须依靠MES系统来管控流程
  7. img垂直居中div - css样式
  8. 详解php概念以及主配置文件
  9. Socket网络编程-UDP编程
  10. 纯数据结构Java实现(10/11)(2-3树&amp;红黑树)