2018 Multi-University Training Contest 9 hdu 6415 Rikka with Nash Equilibrium(规律)

http://acm.hdu.edu.cn/showproblem.php?pid=6415

 

规律题。

需要用大数。

比赛跑2000ms左右的都是c++大数

至于0ms的估计是直接公式。。。

代码是转的java版本。。

 

感觉这种规律是真的想不到。。。

 

import java.math.BigInteger;
import java.awt.Container;
import java.math.*;
import java.math.BigInteger;
import java.util.*;

import org.omg.PortableServer.ID_ASSIGNMENT_POLICY_ID; 
public class Main
{    
     
    
       public static void main(String[] args) 
       {            
           Scanner cin=new Scanner(System.in);
           int t = cin.nextInt();
           for(int i=1;i<=t;i++)
           {
               int n = cin.nextInt();
               int m = cin.nextInt();
               BigInteger k = cin.nextBigInteger();
               
               if(n==1)
               {
                   BigInteger ans = BigInteger.ONE;
                   for(int j=1;j<=m;j++)
                   {
                       ans = ans.multiply(BigInteger.valueOf(j));
                   }
                   ans = ans.mod(k);
                   System.out.println(ans);
               }
               else {
                   BigInteger ans1 = BigInteger.ONE;
                   for(int j=1;j<=n;j++)
                   {
                       ans1 = ans1.multiply(BigInteger.valueOf(j));
                   }
                   
                   //System.out.println(ans1);
                   for(int j=2;j<=m;j++)
                   {
                       BigInteger tt = BigInteger.valueOf(j*n);
                       BigInteger temp = BigInteger.ONE;
                       for(int kk=0;kk<n;kk++)
                       {
                           temp = temp.multiply(tt.subtract(BigInteger.valueOf(kk)));
                       }
                       ans1 = ans1.multiply(temp);
                       ans1 = ans1.multiply(BigInteger.valueOf(j)).divide(BigInteger.valueOf(j+n-1));
                       
                   }
                   ans1 = ans1.mod(k);
                   System.out.println(ans1);
               }
           }
           cin.close();
      }
}

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值