二进制++高精度取模

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std; const int maxn=;
long long a[maxn];
long long sumA[maxn];
int aa,bb;
int len;
long long n; int Base[maxn];
int tot; int ans[maxn]; void init1()
{
memset(sumA,,sizeof sumA);
a[]=;
for(int i=; i<=; i++)
{
a[i]=*a[i-];
sumA[i]=sumA[i-]+a[i];
}
} int main()
{
init1(); int T;
scanf("%d",&T);
while(T--)
{
scanf("%d%d%lld",&aa,&bb,&n);
if(aa>bb) swap(aa,bb);
if(aa&&bb)
{
for(int i=; i<=; i++)
{
if(sumA[i]>=n)
{
int x=(int)(a[i]--(sumA[i]-n));
//printf("%d\n",x);
memset(Base,,sizeof Base);
tot=;
while(x) Base[tot++]=x%,x=x/; len=;
for(int j=i-;j>=;j--)
{
if(Base[j]==) ans[len++]=aa;
else ans[len++]=bb;
}
break;
}
}
}
else
{
memset(Base,,sizeof Base);
tot=;
while(n) Base[tot++]=n%,n=n/;
len=;
for(int i=tot-;i>=;i--)
{
if(Base[i]==) ans[len++]=aa;
else ans[len++]=bb;
}
} long long Ans=;
long long MOD=;
for(int i=;i<len;i++)
{
Ans=Ans*+ans[i];
Ans=Ans%MOD;
}
printf("%lld\n",Ans);
}
return ;
}

BNU OJ 51003 BQG's Confusing Sequence的更多相关文章

  1. BNU OJ 51005 BQG's Quadrilateral Bricks

    #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include ...

  2. BNU OJ 51000 BQG's Random String

    #include<cstdio> #include<cstring> #include<algorithm> using namespace std; +; cha ...

  3. BNU OJ 50999 BQG's Approaching Deadline

    #include<cstdio> #include<algorithm> using namespace std; +; struct Homework { long long ...

  4. BNU OJ 50998 BQG's Messy Code

    #include <cstdio> #define _(l) int l #define ___(l,L) for (_(o)=0,x=l o*2;o<x;o++)O= L o; # ...

  5. BNU OJ 50997 BQG's Programming Contest

    #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> using ...

  6. BNU OJ 33691 / LA 4817 Calculator JAVA大数

    留着当个模板用,在BNU上AC,在LA上RE……可能是java的提交方式不同??? 数和运算符各开一个栈. 表达式从左到右扫一遍,将数存成大数,遇到数压在 数的栈,运算符压在 运算符的栈,每当遇到右括 ...

  7. BNU OJ 1027 金币系统

    金币系统 Time Limit: 1000ms Memory Limit: 65535KB   64-bit integer IO format: %lld      Java class name: ...

  8. bnu oj 13288 Bi-shoe and Phi-shoe

    题目链接: http://www.bnuoj.com/contest/problem_show.php?pid=13288 题目大意: 给出一个n,然后给出n个幸运数([1,m]中不能被m整除的数的数 ...

  9. 面试题目——《剑指Offer》

    1.把一个字符串转换成整数——<剑指Offer>P29 2.求链表中的倒数第k个结点——<剑指Offer>P30 3.实现Singleton模式——<剑指Offer> ...

随机推荐

  1. 给EditText设置边框

    布局文件中加入background属性: <EditText android:layout_width="200dp" android:layout_height=" ...

  2. windows指令

    &        无条件执行&符号后面的命令: &&      当&&前面的命令成功执行时,执行&&后面的命令,否则不执行: ||   ...

  3. protobuf使用NDK编译Android的静态库(工作记录)

    1.protobuf 编译过程 前提: 确保自己电脑上已经安装了cygwin + ndk, 并且NDK能够编译hello-jni成功 1.1 把protobuf 压缩包解压到protobuf文件夹下 ...

  4. OpenGL ES着色器语言之语句和结构体(官方文档第六章)内建变量(官方文档第七、八章)

    OpenGL ES着色器语言之语句和结构体(官方文档第六章) OpenGL ES着色器语言的程序块基本构成如下: 语句和声明 函数定义 选择(if-else) 迭代(for, while, do-wh ...

  5. iOS xcode工程了解

    一个xcode工程默认是在一个主线程的,有需要可以创建分线程 判断是否是主线程: NSThread *thread1=[NSThread currentThread]; if ([red isMain ...

  6. 【转】对于JNI方法名,数据类型和方法签名的一些认识

    [转]对于JNI方法名,数据类型和方法签名的一些认识   之前一直用jni,但是没有考虑Java重载函数,如何在jni-C++里命名,今天看到一篇文章,讲到了类型签名. 原文链接:http://www ...

  7. 根据key存不存在查询json

    select *  from  table where value->'key' != 'null';

  8. bos项目经验心得(1)

    ---恢复内容开始--- 一.搭建数据库环境: 1.在cmd窗口登录mysql数据库: mysql -uroot -proot   (mysql登录数据库的形式就是 mysql-u用户名 -p密码) ...

  9. vmware卸载问题

    1. VMware版本问题:http://www.wuji8.com/meta/15866846.html2. VMware卸载问题:http://www.veryhuo.com/a/view/716 ...

  10. 转: JMeter技巧集锦

    from:http://java.chinaitlab.com/tools/355421.html JMeter 是一个流行的用于负载测试的开源工具, 具有许多有用的功能元件,如线程组(thread ...