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> ...
随机推荐
- Entity Framework 学习高级篇2—改善EF代码的方法(下)
,IQueryable<Customers>>( (database) => database.Customers.Where(c => c.City == " ...
- PHP set_error_handler()函数的使用【转载】
我们写程序,难免会有问题(是经常会遇到问题 ),而PHP遇到错误时,就会给出出错脚本的位置.行数和原因.有很多人说,这并没有什么大不了.确实,在调试程序阶段,这确实是没啥的,而且我认为给出错误路径是必 ...
- wpf CollectionViewSource与ListBox的折叠、分组显示,及输入关键字 Filter的筛选
在wpf中虽然ObservableCollection<T>作为ListBox的Itemsource,很好,很强大!但是CollectionViewSource与ListBox才是天作之合 ...
- auto_ash
#!/usr/bin/ksh ##############paramter######################startdate=$1' 00:00:01'enddate=$2' 23:59: ...
- LightOJ 1370 Bi-shoe and Phi-shoe 数论
题目大意:f(x)=n 代表1-x中与x互质的数字的个数.给出n个数字a[i],要求f(x)=a[i],求x的和. 思路:每个素数x 有x-1个不大于x的互质数.则f(x)=a[i],若a[i]+1为 ...
- Linux标准目录
本文参考鸟哥的linux私房菜 /bin 获得最小的系统可操作性所需要的命令 /boot 内核和加载内核所需要的文件 /dev 终端.磁盘.调制解调器等的设备项 /etc 关键的启动文件和配置文件 / ...
- Properties集合
Map |--Hashtable |--Properties Properties集合特点: 1.该集合中的键和值都是字符串类型 2.集合中的数据可以保存在IO流中或者从IO流中获取数据. 通常该集合 ...
- java的两种异常runtimeException和checkedException
java异常处理机制主要依赖于try,catch,finally,throw,throws五个关键字. try 关键字后紧跟一个花括号括起来的代码块,简称try块.同理:下面的也被称为相应的块. ...
- MySQL操作失误导致mysql数据库查看不了
使用 show databases; +--------------------+| Database |+--------------------+| information_ ...
- Provisioning profile 浅析
转载自: http://blog.csdn.net/chenyufeng1991/article/details/48976245 一般在我们代码编写中不会用到Provisioning prof ...