Generation I
Generation I
Now Oak is going to do N operations. In the i-th operation, he will insert an integer x between 1 and M to every set indexed between i and N.
Oak wonders how many different results he can make after the N operations. Two results are different if and only if there exists a set in one result different from the set with the same index in another result.
Please help Oak calculate the answer. As the answer can be extremely large, output it modulo 998244353.
输入描述:
The input starts with one line containing exactly one integer T which is the number of test cases. (1 ≤ T ≤ 20) Each test case contains one line with two integers N and M indicating the number of sets and the range of integers.
(1 ≤ N ≤ 1018, 1 ≤ M ≤ 1018,)
输出描述:
For each test case, output "Case #x: y" in one line (without quotes), where x is the test case number (starting from 1) and y is the number of different results
modulo 998244353.
输入
2
2 2
3 4
输出
Case #1: 4
Case #2: 52


#include <iostream>
#define N 1000005
using namespace std;
const long long mod=;
long long ny[N+];
long long f(long long a,long long b)
{
long long ans=;
while(b>)
{
if(b%==)ans=(ans*a)%mod; b/=;
a=(a*a)%mod;
}
return ans;
} int main()
{
int t,tot=;
scanf("%d",&t);
for(int i=;i<=N;i++)ny[i]=f(i,mod-); while(t--)
{
long long n,m,ans,upper,last;
scanf("%lld %lld",&n,&m); upper=min(n,m);
ans=last=m%mod; for(int i=;i<=upper;i++)
{
last*=(m+-i)%mod;
last%=mod;
last*=ny[i-];
last%=mod;
last*=(n+-i)%mod;
last%=mod;
ans+=last;
ans%=mod;
} printf("Case #%d: %lld\n",++tot,ans);
}
return ;
}
Generation I的更多相关文章
- 论文阅读(Zhuoyao Zhong——【aixiv2016】DeepText A Unified Framework for Text Proposal Generation and Text Detection in Natural Images)
Zhuoyao Zhong--[aixiv2016]DeepText A Unified Framework for Text Proposal Generation and Text Detecti ...
- Task set generation
Task set generation for uni- and multiprocessors: “Unifying Fixed- and Dynamic-Priority Scheduling b ...
- 使用-MM生成include指令和依赖生成(make include directive and dependency generation with -MM)
I want a build rule to be triggered by an include directive if the target of the include is out of d ...
- PHPNG (next generation)
PHPNG (next generation) This page gives short information about development state of a new PHP branc ...
- test generation和MBIST
The problem of test generation Random test generation Deterministic algorithm for test generation fo ...
- 关于conversation generation的论文笔记
对话模型此前的研究大致有三个方向:基于规则.基于信息检索.基于机器翻译.基于规则的对话系统,顾名思义,依赖于人们周密设计的规则,对话内容限制在特定领域下,实际应用如智能客服,智能场馆预定系统.基于信息 ...
- 1094. The Largest Generation (25)
A family hierarchy is usually presented by a pedigree tree where all the nodes on the same level bel ...
- Case Study: Random Number Generation(翻译教材)
很荣幸,经过三天的努力.终于把自己翻译的教材做完了,现在把它贴出来,希望能指出其中的不足. Case Study: Random Number Generation Fig. 6.7 C++ 标 ...
- Index Generation
Index Generation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 230 Accepted: 89 Des ...
- PowerDesigner15(16)在生成SQL时报错Generation aborted due to errors detected during the verification of the mod
1.用PowerDesigner15建模,在Database—>Generate Database (或者用Ctrl+G快捷键)来生产sql语句,却提示“Generation aborted d ...
随机推荐
- Lesson1
#ifdef __cplusplus #include <cstdlib> #else #include <stdlib.h> #endif #include <SDL/ ...
- js 前端不调接口直接下载图片
// 下载图片 downPhoto (path) { this.downloadFiles(path) }, // 下载 downloadFiles (content) { console.log(c ...
- Hibernate中get()与load()的区别,以及关于ThreadLocal的使用方法
一.get方法和load方法的简易理解 (1)get()方法直接返回实体类,如果查不到数据则返回null.load()会返回一个实体代理对象(当前这个对象可以自动转化为实体对象),但当代理对象被调用时 ...
- bootstrap历练实例: 垂直胶囊式的导航菜单
<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content=&q ...
- 基于Passthru的NDIS开发的个人理解
这几天对NDIS的学习,基本思路是:首先熟悉理论知识→然后下载一个例子进行研究→最后例子自己模仿扩展→最最后尝试自己写一个新的. Passthru是微软NDIS自己写的一个框架驱动,NDIS开发者可以 ...
- 用xtrabackup实现mysql的主从复制 阿里云rds到自己创建mysql
来源 http://blog.51cto.com/825536458/1803968参考https://segmentfault.com/a/1190000003063874 如果我们用传统的mysq ...
- MariaDB数据库(三)
1. 基本查询 查询基本使用包括:条件.排序.聚合函数.分组和分页. 实例详解查询 1> 创建students表用作实验 MariaDB [testdb]> drop table stud ...
- 一次下载多个文件的解决思路-JS
一次下载多个文件的解决思路(iframe) - Eric 真实经历 最近开发项目需要做文件下载,想想挺简单的,之前也做过,后台提供下载接口,前端使用window.location.href就行了呗.不 ...
- 常用JS方法整理
目录: 截取指定字节数的字符串 判断是否微信 获取时间格式的几个举例 获取字符串字节长度 对象克隆.深拷贝 组织结构代码证验证 身份证号验证 js正则为url添加http标识 URL有效性校验方法 自 ...
- Python基本运算符和流程控制
常量 常量即不可改变的量,在Python中不存在常量,我们只能逻辑上规定一个常量并不去修改它,通常用全大写字母表示. 基本运算符之二 算术运算 运算符 说明 ** 幂运算 *, /, //, % 乘. ...