多校6 A Boring Question 5793

A Boring Question

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 635    Accepted Submission(s): 375


Problem Description
There are an equation.
0k1,k2,kmn1j<m(kj+1kj)%1000000007=?
We define that (kj+1kj)=kj+1!kj!(kj+1kj)! . And (kj+1kj)=0 while kj+1<kj .
You have to get the answer for each n and m that given to you.
For example,if n=1 , m=3 ,
When k1=0,k2=0,k3=0,(k2k1)(k3k2)=1 ;
When k1=0,k2=1,k3=0,(k2k1)(k3k2)=0 ;
When k1=1,k2=0,k3=0,(k2k1)(k3k2)=0 ;
When k1=1,k2=1,k3=0,(k2k1)(k3k2)=0 ;
When k1=0,k2=0,k3=1,(k2k1)(k3k2)=1 ;
When k1=0,k2=1,k3=1,(k2k1)(k3k2)=1 ;
When k1=1,k2=0,k3=1,(k2k1)(k3k2)=0 ;
When k1=1,k2=1,k3=1,(k2k1)(k3k2)=1 .
So the answer is 4.
 

Input
The first line of the input contains the only integer T , (1T10000)
Then T lines follow,the i-th line contains two integers n , m , (0n109,2m109)
 

Output
For each n and m ,output the answer in a single line.
 

Sample Input
  
  
2 1 2 2 3
 

Sample Output
  
  
3 13
 




代码:


#include <algorithm>
#include <cstdio>
#include <vector>
#include <iostream>

using namespace std;

const int mod = 1000000007;
int n,m;

 long long quickmod(long long a,long long b)
{
    long long ans = 1;
    while(b)//用一个循环从右到左便利b的所有二进制位
    {
        if(b&1)//判断此时b[i]的二进制位是否为1
        {
            ans = (ans*a)%mod;//乘到结果上,这里a是a^(2^i)%m
            b--;//把该为变0
        }
        b/=2;
        a = a*a%mod;
    }
    return ans;
}

int main()
{
    int t;
    cin>>t;
    while(t--)
    {
         cin>>n>>m;
         cout<<(long long)((quickmod(m,n+1)-1)%mod*(quickmod(m-1,mod-2)%mod))%mod<<endl;
    }
    return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值