二进制++高精度取模

#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. htaccess 实现网址缩短

    访问 :app.xxx.com/a 解析到:app.xxx.com/index.php/app/a <IfModule mod_rewrite.c> RewriteEngine on Re ...

  2. docker installation on ubuntu

    Ubuntu Docker is supported on these Ubuntu operating systems: Ubuntu Xenial 16.04 (LTS) Ubuntu Trust ...

  3. SQL的自增列重置的方法

    SQL的自增列挺好用,只是开发过程中一旦删除数据,标识列就不连续了 写起来 也很郁闷,所以查阅了一下标识列重置的方法 发现可以分为三种: --- 删除原表数据,并重置自增列 truncate tabl ...

  4. opatch auto in windows db in 11.2.0.4

    --prapare:copy 192.168.63.83 D:\oracle_patch\1612 to 192.168.2.169 D:\oracle_patch\1612cd D:\oracle_ ...

  5. ant 配置expdp and impap

    + 执行步骤: ant -f 1_exp_prod.xml copy file from prod to uat (maunule) ant -f  3_imp_uat.xml 附件: 1.1_exp ...

  6. 【HDU 5833】Zhu and 772002(异或方程组高斯消元讲解)

    题目大意:给出n个数字a[],将a[]分解为质因子(保证分解所得的质因子不大于2000),任选一个或多个质因子,使其乘积为完全平方数.求其方法数. 学长学姐们比赛时做的,当时我一脸懵逼的不会搞……所以 ...

  7. Smoke Testing(冒烟测试)

    Smoke Testing 的概念最早源于制造业,用于测试管道.测试时,用鼓风机往管道里灌烟,看管壁外面是否有烟冒出来,以便检验管道是否有缝隙.这一测试显然比较初级,更深层一点的测试至少要进行渗油测试 ...

  8. 下拉刷新和上拉加载 Swift

    转载自:http://iyiming.me/blog/2015/07/05/custom-refresh-and-loading/ 关于下拉刷新和上拉加载,项目中一直使用MJRefresh(原先还用过 ...

  9. 设置控件全局显示样式 appearance

    iOS5及其以后提供了一个比较强大的工具UIAppearance,我们通过UIAppearance设置一些UI的全局效果,这样就可以很方便的实现UI的自定义效果又能最简单的实现统一界面风格,它提供如下 ...

  10. java断点

    第一步: 用firefox运行程序,当点击保存,提示保存失败后,启动firebug 通过请求找到addNew.ezt出现错误,在eztnews.xml里通过ctrl+F查找找到请求执行的类和方法 找到 ...