CCF_201912-5试题及答案(Java )

题目

分析

这一题只要按照题目所给的流程计算就行,大整数用BigInteger进行处理就行了,难就难在如何进行优化以缩短运行时间,我本来打算自己写对大整数的处理,但是发现效率还不如BigInteger自带的处理函数,所以到最后也就放弃了,拿了个25分,所以这道题想拿分挺容易的,但是想拿满分挺难的,但是考场上可能很多同学不会去看第五题,或者看了一眼觉得没怎么理解就放弃了,也是挺可惜的。

代码

import java.util.Scanner;
import java.math.BigInteger;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stubL
		BigInteger u0=BigInteger.valueOf(314882150829468584L);
		BigInteger u1=BigInteger.valueOf(427197303358170108L);
		BigInteger u2=BigInteger.valueOf(1022292690726729920L);
		BigInteger u3=BigInteger.valueOf(1698479428772363217L);
		BigInteger u4=BigInteger.valueOf(2006101093849356424L);
		BigInteger u5=BigInteger.valueOf(2009731336725594113L);
		BigInteger[] u = {u0,u1,u2,u3,u4};
		BigInteger tn=new BigInteger("2019");	
		BigInteger five = new BigInteger("5");	
		
		Scanner sca=new Scanner(System.in);
		int n=sca.nextInt();
		int q=sca.nextInt();
		BigInteger[] score=new BigInteger[n];
		for(int i=1;i<=n;i++)
			score[i-1]=BigInteger.valueOf(i);
		for(int i=0;i<q;i++) {
			int l=sca.nextInt();
			int r=sca.nextInt();
			BigInteger s=BigInteger.valueOf(0);
			for(int j=l;j<=r;j++)
				s=s.add(score[j-1].remainder(tn));	
			System.out.println(s);
			int t=s.remainder(five).intValue();
			for(;l<=r;l++)
				score[l-1]=score[l-1].multiply(u[t]).remainder(u5);
		}
		sca.close();
	}
}

结果

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值