题目连接

http://acm.hdu.edu.cn/showproblem.php?pid=1212

Big Number

Description

As we know, Big Number is always troublesome. But it's really important in our ACM. And today, your task is to write a program to calculate A mod B.

To make the problem easier, I promise that B will be smaller than 100000.

Is it too hard? No, I work it out in 10 minutes, and my program contains less than 25 lines.

Input

The input contains several test cases. Each test case consists of two positive integers A and B. The length of A will not exceed 1000, and B will be smaller than 100000. Process to the end of file.

Output

For each test case, you have to ouput the result of A mod B.

SampleInput

2 3
12 7
152455856554521 3250

SampleOutput

2
5
1521

大数取余模板题。。

 #include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cassert>
#include<cstdio>
#include<vector>
#include<string>
#include<map>
#include<set>
using std::cin;
using std::max;
using std::cout;
using std::endl;
using std::string;
using std::istream;
using std::ostream;
#define sz(c) (int)(c).size()
#define all(c) (c).begin(), (c).end()
#define iter(c) decltype((c).begin())
#define cls(arr,val) memset(arr,val,sizeof(arr))
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define fork(i, k, n) for (int i = (int)k; i <= (int)n; i++)
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
struct BigN {
typedef unsigned long long ull;
static const int Max_N = ;
int len, data[Max_N];
BigN() { memset(data, , sizeof(data)), len = ; }
BigN(const int num) {
memset(data, , sizeof(data));
*this = num;
}
BigN(const char *num) {
memset(data, , sizeof(data));
*this = num;
}
void clear() { len = , memset(data, , sizeof(data)); }
BigN& clean(){ while (len > && !data[len - ]) len--; return *this; }
string str() const {
string res = "";
for (int i = len - ; ~i; i--) res += (char)(data[i] + '');
if (res == "") res = "";
res.reserve();
return res;
}
BigN operator = (const int num) {
int j = , i = num;
do data[j++] = i % ; while (i /= );
len = j;
return *this;
}
BigN operator = (const char *num) {
len = strlen(num);
for (int i = ; i < len; i++) data[i] = num[len - i - ] - '';
return *this;
}
BigN operator + (const BigN &x) const {
BigN res;
int n = max(len, x.len) + ;
for (int i = , g = ; i < n; i++) {
int c = data[i] + x.data[i] + g;
res.data[res.len++] = c % ;
g = c / ;
}
return res.clean();
}
BigN operator * (const BigN &x) const {
BigN res;
int n = x.len;
res.len = n + len;
for (int i = ; i < len; i++) {
for (int j = , g = ; j < n; j++) {
res.data[i + j] += data[i] * x.data[j];
}
}
for (int i = ; i < res.len - ; i++) {
res.data[i + ] += res.data[i] / ;
res.data[i] %= ;
}
return res.clean();
}
BigN operator * (const int num) const {
BigN res;
res.len = len + ;
for (int i = , g = ; i < len; i++) res.data[i] *= num;
for (int i = ; i < res.len - ; i++) {
res.data[i + ] += res.data[i] / ;
res.data[i] %= ;
}
return res.clean();
}
BigN operator - (const BigN &x) const {
assert(x <= *this);
BigN res;
for (int i = , g = ; i < len; i++) {
int c = data[i] - g;
if (i < x.len) c -= x.data[i];
if (c >= ) g = ;
else g = , c += ;
res.data[res.len++] = c;
}
return res.clean();
}
BigN operator / (const BigN &x) const {
BigN res, f = ;
for (int i = len - ; ~i; i--) {
f *= ;
f.data[] = data[i];
while (f >= x) {
f -= x;
res.data[i]++;
}
}
res.len = len;
return res.clean();
}
BigN operator % (const BigN &x) {
BigN res = *this / x;
res = *this - res * x;
return res;
}
BigN operator += (const BigN &x) { return *this = *this + x; }
BigN operator *= (const BigN &x) { return *this = *this * x; }
BigN operator -= (const BigN &x) { return *this = *this - x; }
BigN operator /= (const BigN &x) { return *this = *this / x; }
BigN operator %= (const BigN &x) { return *this = *this % x; }
bool operator < (const BigN &x) const {
if (len != x.len) return len < x.len;
for (int i = len - ; ~i; i--) {
if (data[i] != x.data[i]) return data[i] < x.data[i];
}
return false;
}
bool operator >(const BigN &x) const { return x < *this; }
bool operator<=(const BigN &x) const { return !(x < *this); }
bool operator>=(const BigN &x) const { return !(*this < x); }
bool operator!=(const BigN &x) const { return x < *this || *this < x; }
bool operator==(const BigN &x) const { return !(x < *this) && !(x > *this); }
friend istream& operator >> (istream &in, BigN &x) {
string src;
in >> src;
x = src.c_str();
return in;
}
friend ostream& operator << (ostream &out, const BigN &x) {
out << x.str();
return out;
}
}A[];
int main() {
#ifdef LOCAL
freopen("in.txt", "r", stdin);
freopen("out.txt", "w+", stdout);
#endif
std::ios::sync_with_stdio(false);
while (cin >> A[] >> A[]) {
cout << A[] % A[] << endl;
rep(i, ) A[i].clear();
}
return ;
}

hdu 1212 Big Number的更多相关文章

  1. HDU 1212 Big Number(C++ 大数取模)(java 大数类运用)

    Big Number 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1212 ——每天在线,欢迎留言谈论. 题目大意: 给你两个数 n1,n2.其中n1 ...

  2. HDU 1212 Big Number 大数模小数

    http://acm.hdu.edu.cn/showproblem.php?pid=1212 题目大意: 给你一个长度不超过1000的大数A,还有一个不超过100000的B,让你快速求A % B. 什 ...

  3. hdu 1212 Big Number(大数取模)

    Problem Description As we know, Big Number is always troublesome. But it's really important in our A ...

  4. 题解报告:hdu 1212 Big Number(大数取模+同余定理)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1212 Problem Description As we know, Big Number is al ...

  5. hdu 5898 odd-even number 数位DP

    传送门:hdu 5898 odd-even number 思路:数位DP,套着数位DP的模板搞一发就可以了不过要注意前导0的处理,dp[pos][pre][status][ze] pos:当前处理的位 ...

  6. hdu 2665 Kth number

    划分树 /* HDU 2665 Kth number 划分树 */ #include<stdio.h> #include<iostream> #include<strin ...

  7. hdu 4670 Cube number on a tree(点分治)

    Cube number on a tree Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/ ...

  8. 主席树[可持久化线段树](hdu 2665 Kth number、SP 10628 Count on a tree、ZOJ 2112 Dynamic Rankings、codeforces 813E Army Creation、codeforces960F:Pathwalks )

    在今天三黑(恶意评分刷上去的那种)两紫的智推中,突然出现了P3834 [模板]可持久化线段树 1(主席树)就突然有了不详的预感2333 果然...然后我gg了!被大佬虐了! hdu 2665 Kth ...

  9. HDU - 1711 A - Number Sequence(kmp

    HDU - 1711 A - Number Sequence   Given two sequences of numbers : a[1], a[2], ...... , a[N], and b[1 ...

随机推荐

  1. 利用KeyVault来加强存储Azure Storage访问密钥管理

    很多时候管理Azure的存储账号我们都需要通过下面的界面管理访问密钥,大部分情况下通过密钥的轮替使用更新就可以做到安全管理了. 但是很多时候存储账号的Key就会不小心分发到开人员.测试人员.和管理员手 ...

  2. Laxcus大数据管理系统2.0(8)- 第六章 网络通信

    第六章 网络通信 Laxcus大数据管理系统网络建立在TCP/IP网络之上,从2.0版本开始,同时支持IPv4和IPv6两种网络地址.网络通信是Laxcus体系里最基础和重要的一环,为了能够利用有限的 ...

  3. ionic icons and splash

    ionic 用cordova  可以直接设置自己的icons ,不用修改默认的图片了 1.在自己的根目录下新建一个文件夹 如icons 2.然后在icons文件夹下再建一个iOS 文件夹存放所需要的图 ...

  4. 自适应中overflow的作用

    最近在做东西的时候发现overflow还有这样的妙处:可以实现自适应,之前没加overflow实现起来是有点问题的 代码如下: <!DOCTYPE html><html> &l ...

  5. openSUSE之SSH登录

    环境: 1:操作系统:openSUSE 2:SSH工具:Xshell 3:virtualbox 解决问题:Xshell通过ssh登录openSUSE进行操作. 1:virtualbox安装好openS ...

  6. oracle 如何恢复误删的表记录数据

    --开启行移动功能 ALTER TABLE tablename ENABLE row movement ; --恢复表数据,时间为删除或修改的时间点 flashback table tablename ...

  7. 查看cics 运行状态

     查看cics 运行状态cicscp -v status all 

  8. 第五章_PHP流程控制

    1.顺序结构 2.分支结构 2.1 if...else <?php $today=date("w"); //获取今天星期几 if($today==0){ echo 'Sund ...

  9. Mysql 复制工具(percona-toolkit)

    Mysql 复制工具 1.percona-toolkit简介 percona-toolkit是一组高级命令行工具的集合,用来执行各种通过手工执行非常复杂和麻烦的mysql和系统任务,这些任务包括: 检 ...

  10. 消息推送之GCM

    利用GCM进行消息推送 原理 1.接收端向GCM注册registerid 2.发送端发消息给GCM服务器 这个过程需要三个参数: (1)API Key (2)registerid (3)传递的数据 3 ...