没有合适的资源?快使用搜索试试~ 我知道了~
acm程序例题2道,还有一道思考的题目(第四题)
需积分: 10 1 下载量 37 浏览量
2010-04-08
18:36:15
上传
评论
收藏 8KB TXT 举报
温馨提示
试读
8页
这个是对于一道acm程序设计中的一道题,同时在解题同时还引出了第四题
资源推荐
资源详情
资源评论
1.Description
A big integer with most of its digits being zeros is called a sparse big integer. Given a sparse big integer M and an integer N, you are to calculate M mod N.
Input
The first line contains an integer representing the number of test cases. Each test case consists of two lines. In the first line of a test case, an integer K will be given first; then K pairs of integers follow, each indicates a non-zero digit with two integers D and P, which means the P-th digit of M from right to left is D. In the second line, the integer N will be given.
1 <= K <= 10; 1 <= D <= 9; 1 <= P <= 1000000000; 1 <= N <= 10000.
Output
For each test case, print the result of M mod N in a single line.
Sample Input
1
2 1 6 1 8
2046
Sample Output
944
//cpp文件
#include "stdafx.h"
#include "SparseBigInteger.h"
#include <algorithm>
#include <iostream>
#include <map>
A big integer with most of its digits being zeros is called a sparse big integer. Given a sparse big integer M and an integer N, you are to calculate M mod N.
Input
The first line contains an integer representing the number of test cases. Each test case consists of two lines. In the first line of a test case, an integer K will be given first; then K pairs of integers follow, each indicates a non-zero digit with two integers D and P, which means the P-th digit of M from right to left is D. In the second line, the integer N will be given.
1 <= K <= 10; 1 <= D <= 9; 1 <= P <= 1000000000; 1 <= N <= 10000.
Output
For each test case, print the result of M mod N in a single line.
Sample Input
1
2 1 6 1 8
2046
Sample Output
944
//cpp文件
#include "stdafx.h"
#include "SparseBigInteger.h"
#include <algorithm>
#include <iostream>
#include <map>
using namespace std;
static int loop_count = 0;
long lpow(long v, long fa, long n)
{
map<long, long> series;
long r = 1;
long se = 0;
for (long f = 0; f < fa; f++)
{
++loop_count;
series[r] = se++;
r *= v;
r %= n;
if (series.find(r) != series.end())
{
r *= lpow(v, (fa - series[r]) % (se - series[r]), n);
break;
}
}
return r % n;
}
inline
long impmod(long restdig, long n)
{
long d = restdig / DECS;
long m = restdig % DECS;
long mod = lpow(fpow[DECS] % n, d, n) % n;
剩余7页未读,继续阅读
资源评论
oupq42132
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- DSP开发实战教程-国产DSP替代进口TI DSP的使用技巧 进芯DSP替换文件
- 植被恢复能力估算python代码(KNDVI代码).zip
- 基于java打造的深度学习框架,帮助你快速搭建神经网络,实现模型推理与训练,引擎支持自动求导,多线程与GPU运算
- 界线与不动产测绘智能计算经纬度及标注软件
- CANOPEN使用方法与教程
- 极影毁片圆 · 电脑字体设置.zip
- 同态加密部分算法实现Homomorphic-Encryption-main.zip
- helib同态加密socket通信helibsocket-master.zip
- pll_inst.vhd
- 快速入门同态加密homomorphic-encryption-master.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功