二进制++高精度取模

#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. Linux Ubuntu 内核升级

    方法一 : 1 更新系统源 apt-get update 2 搜索内核文件 apt-cache search linux-image 3 安装 apt-get install -y  linux-im ...

  2. ecshop 去版权

    与官网通信的几个地方: 1,打开admin/templates/index.htm,查找并删除 <frameset rows="0, 0" framespacing=&quo ...

  3. 使用onclick跳转到其他页面。使用button跳转到指定url

    1. onclick="javascript:window.location.href='aa.htm'" 2.  onclick="location='URL'&quo ...

  4. Inno Setup入门(十四)——替换安装程序和卸载程序的图标

    通常Inno生成的安装文件的图标是一个光盘和显示器,如下图.同时,程序安装好之后,在安装目录下的卸载程序的图标也是一样的,其实我们也可以自己修改. 首先生成的安装文件图标.这个比较简单,只需要在Set ...

  5. 【素数】 poj 2739 一个数能有多少种连续素数相加方案

    简单题 素数打表   根据数据量  用n2算法遍历  开一个save[k]素数存前k个素数和即可. #include <iostream> #include <cstdio> ...

  6. C# 垃圾回收机制(转)

    摘要:今天我们漫谈C#中的垃圾回收机制,本文将从垃圾回收机制的原理讲起,希望对大家有所帮助. GC的前世与今生 虽然本文是以.NET作为目标来讲述GC,但是GC的概念并非才诞生不久.早在1958年,由 ...

  7. Spring Boot 系列教程17-Cache-缓存

    缓存 缓存就是数据交换的缓冲区(称作Cache),当某一硬件要读取数据时,会首先从缓存中查找需要的数据,如果找到了则直接执行,找不到的话则从内存中找.由于缓存的运行速度比内存快得多,故缓存的作用就是帮 ...

  8. POJ 1308/并查集

    题目链接 /* 判断一棵树: * 1.There is exactly one node, called the root, to which no directed edges point. * 2 ...

  9. fidder 调接口 的 小常识

    fidder   调试接口 进入fidder页面   点击 composer Content-Type: application/x-www-form-urlencoded; charset=UTF- ...

  10. java 实例方法和类方法的区别