hdu 3398
String
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2161 Accepted Submission(s): 628
lxhgww received a task : to generate strings contain '0's and '1's
only, in which '0' appears exactly m times, '1' appears exactly n times.
Also, any prefix string of it must satisfy the situation that the
number of 1's can not be smaller than the number of 0's . But he can't
calculate the number of satisfied strings. Can you help him?
Each case contains two numbers n and m( 1 <= m <= n <= 1000000 ).
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cstdlib>
using namespace std;
typedef long long LL;
const long long mod = ; bool s[];
int prime[],len;
void Init(){
int i,j;
memset(s,false,sizeof(s));
len=;
for(i=;i<=;i++)
{
if(s[i]==true) continue;
prime[++len]=i;
if(i>) return;
for(j=i*;j<=;j=j+i)
s[j]=true;
}
}
int get_num(int n,int m){
int ans=;
while(n){
n=n/m;
ans=ans+n;
}
return ans;
}
LL pow_mod(LL a,LL b)
{
LL ans=;
while(b)
{
if(b&){
ans=(ans*a)%mod;
}
b=b>>;
a=(a*a)%mod;
}
return ans;
} void solve(int n,int m){
int ans;
LL sum1=,sum2=;
for(int i=;i<=len;i++)
{
if(prime[i]>n+m)break;
ans=get_num(n+m,prime[i])-get_num(n,prime[i])-get_num(m,prime[i]);
sum1=(sum1*pow_mod(prime[i],ans))%mod; ans=get_num(n+m,prime[i])-get_num(n+,prime[i])-get_num(m-,prime[i]);
sum2=(sum2*pow_mod(prime[i],ans))%mod;
}
// printf("%lld %lld\n",sum1,sum2);
if(sum1<sum2) sum1=sum1-sum2+mod;
else sum1=sum1-sum2;
printf("%lld\n",sum1);
}
int main()
{
Init();
int T,n,m;
scanf("%d",&T);
while(T--){
scanf("%d%d",&n,&m);
solve(n,m);
}
return ;
}
hdu 3398的更多相关文章
- HDU 3398 String
题目大意:一个长为n的01字符串,使前缀任意0的数量不大于1的数量,求方案数…… 题解:高一模拟赛时做过,是卡特兰数的几何意义,将字符串变为矩阵寻路,不可越过对角线,那么就是卡特兰数了,C(n+m, ...
- HDU题解索引
HDU 1000 A + B Problem I/O HDU 1001 Sum Problem 数学 HDU 1002 A + B Problem II 高精度加法 HDU 1003 Maxsu ...
- 转载:hdu 题目分类 (侵删)
转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- HDU 4006The kth great number(K大数 +小顶堆)
The kth great number Time Limit:1000MS Memory Limit:65768KB 64bit IO Format:%I64d & %I64 ...
- HDU 1796How many integers can you find(容斥原理)
How many integers can you find Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d ...
随机推荐
- [原创]java WEB学习笔记70:Struts2 学习之路-- 输入验证,声明式验证,声明是验证原理
本博客的目的:①总结自己的学习过程,相当于学习笔记 ②将自己的经验分享给大家,相互学习,互相交流,不可商用 内容难免出现问题,欢迎指正,交流,探讨,可以留言,也可以通过以下方式联系. 本人互联网技术爱 ...
- [转]有哪些值得关注的技术博客(Java篇)
有哪些值得关注的技术博客(Java篇) 大部分程序员在自学的道路上不知道走了多少坑,这个视频那个网站搞得自己晕头转向.对我个人来说我平常在学习的过程中喜欢看一些教程式的博客.这些博客的特点: 1. ...
- java的I/O操作:文件的路径
package solutions; import java.io.*; /** * Created by Administrator on 2016/3/14. */ public class Re ...
- << 链式重载
#include <iostream> using namespace std; class Complex { private: int a, b; public: Complex(in ...
- bzoj3304 [Shoi2005]带限制的最长公共子序列
dp,时间复杂度O(n^3),f[i][j][k]表示a串到i,b串到j的时候,匹配了c串的k位,要用滚动数组 代码 #include<cstring> #include<algor ...
- PHP浮点数的一个常见问题的解答 (转载 http://www.laruence.com/2013/03/26/2884.html)
不过, 我当时遗漏了一点, 也就是对于如下的这个常见问题的回答: <?php $f = 0.58; var_dump(intval($f * 100)); //为啥输出57 ?> 为啥输出 ...
- 【转】C#访问权限修饰符
C#访问权限修饰符 C#中类及类型成员修饰符有以下四类:public,private,protected,internal. public 类及类型成员的修饰符 private 类型成员 ...
- Fragement
package com.exmple.frage; import java.util.ArrayList; import java.util.Calendar; import java.util.Ha ...
- android 项目学习随笔九(ListView加头布局)
1.缓冲背景色 <ListView android:id="@+id/lv_list" android:layout_width="match_parent&quo ...
- THE HANDLER_READ_* STATUS VARIABLES
Because I do a lot of Performance Tuning gigs I get often in contact with these status variables. In ...