BNU OJ 51003 BQG's Confusing Sequence
二进制++高精度取模
#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的更多相关文章
- BNU OJ 51005 BQG's Quadrilateral Bricks
#include<cstdio> #include<cstring> #include<cmath> #include<vector> #include ...
- BNU OJ 51000 BQG's Random String
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; +; cha ...
- BNU OJ 50999 BQG's Approaching Deadline
#include<cstdio> #include<algorithm> using namespace std; +; struct Homework { long long ...
- 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; # ...
- BNU OJ 50997 BQG's Programming Contest
#include<cstdio> #include<cstring> #include<cmath> #include<algorithm> using ...
- BNU OJ 33691 / LA 4817 Calculator JAVA大数
留着当个模板用,在BNU上AC,在LA上RE……可能是java的提交方式不同??? 数和运算符各开一个栈. 表达式从左到右扫一遍,将数存成大数,遇到数压在 数的栈,运算符压在 运算符的栈,每当遇到右括 ...
- BNU OJ 1027 金币系统
金币系统 Time Limit: 1000ms Memory Limit: 65535KB 64-bit integer IO format: %lld Java class name: ...
- bnu oj 13288 Bi-shoe and Phi-shoe
题目链接: http://www.bnuoj.com/contest/problem_show.php?pid=13288 题目大意: 给出一个n,然后给出n个幸运数([1,m]中不能被m整除的数的数 ...
- 面试题目——《剑指Offer》
1.把一个字符串转换成整数——<剑指Offer>P29 2.求链表中的倒数第k个结点——<剑指Offer>P30 3.实现Singleton模式——<剑指Offer> ...
随机推荐
- CentOS 7 BIND 主从搭建
主机 10.2.0.15 从机 10.2.0.14 1 主机配置$vim /etc/named.bodani.com.zones zone"bodani.com" IN { typ ...
- make module失败的原因cc1: error: unrecognized command line option “-m64
cc1: error: unrecognized command line option "-m64"cc1: error: unrecognized command line o ...
- http get with body data
http://stackoverflow.com/questions/978061/http-get-with-request-body Yes, you can send a request bod ...
- 事件委托小demo(jq版)
<style type="text/css"> * { margin:; padding:; } .box1 { width: 200px; height: 60px; ...
- apicloud教程1 (转载)
非常感谢APICloud官方给我版主职位,每天都看到很多朋友提出很多问题,我就借此机会写了一系列的教程,帮助大家从小白到高手之路.系列名称:<APICloud之小白图解教程系列>,会不定时 ...
- Android OpenGL ES(十一)绘制一个20面体 .
前面介绍了OpenGL ES所有能够绘制的基本图形,点,线段和三角形.其它所有复杂的2D或3D图形都是由这些基本图形构成. 本例介绍如何使用三角形构造一个正20面体.一个正20面体,有12个顶点,20 ...
- Object对象
1.Object类:所有类的根类.是不断抽取而来的,具备所有对象都具有的共性内容.其中的方法,任何对象都可以调用.继承而来的. equals()方法: Object类的equals源码:比较两个对象是 ...
- merge 语句的语法
/*Merge into 详细介绍 MERGE语句是Oracle9i新增的语法,用来合并UPDATE和INSERT语句. 通过MERGE语句,根据一张表或子查询的连接条件对另外一张表进行查询, 连接条 ...
- python解析XML之ElementTree
#coding=utf-8 from xml.etree import ElementTree as ET tree=ET.parse('test.xml') root = tree.getroot( ...
- 初识Selenium(三)
浅谈基于Selenium的Web自动化测试框架 发表于:2011-4-25 10:58 作者:邵育亮 来源:51Testing软件测试网原创 字体:大 中 小 | 上一篇 | 下一篇 | 打印 ...