1
7
2016
1

codeforces.com/contest/185/problem/D

题面 戳我 题解 戳我

题目大意

105组询问

每次给你k,l,r,p

LCM(k2l + 1, k2l + 1 + 1, ..., k2r + 1)%p

(1 ≤ ki ≤ 1060 ≤ li ≤ ri ≤ 1018; 2 ≤ pi ≤ 109)cf的字体好好看啊

第一眼看上去神题啊QAQ

想了下估计一堆数的lcm肯定是有性质的

猜了下大概gcd是1或者2

然而数学太差不会证

vp结束后看了下题解算是搞懂了

Let . Squaring both sides we get , but we want to . This means, that d can be only 2.

,左右平方得到,但是我们想让所以d只能是2

然后问题就变成了计算那一堆数字的乘积

不难发现这是只等比数列

套下公式计算下就好了

细节有点复杂导致vp2h内没写出有些悲伤

#include <stdio.h>
#include <algorithm>
using namespace std;
int t;
long long k,l,r,p,a,b,h;
long long ksm(long long x,long long y,long long mo){
	long long k=1;
	for(;y;y>>=1){
		if(y&1)k=1ll*k*x%mo;
		x=1ll*x*x%mo; 
	}
	return k;
}
int main(){
	scanf("%d",&t);
	for(;t;t--){
		scanf("%I64d%I64d%I64d%I64d",&k,&l,&r,&p);
		if(p==2){if(k&1)printf("0\n");else printf("1\n");continue;}
		if(k==1){printf("%I64d\n",2%p);continue;}
		h=1;
		if(k&1)h=ksm(ksm(2,p-2,p),r-l,p);
		if(k%p==0){
			printf("%I64d\n",h);continue;
		}
		else {
			a=ksm(k,ksm(2,r+1,p-1),p)-1;
			b=ksm(k,ksm(2,l,p-1),p)-1;
			if(!b)printf("%I64d\n",ksm(2,r-l+1,p)*h%p);
			else printf("%I64d\n",h*a%p*ksm(b,p-2,p)%p);
		}
	}
	
	return 0;
}
Category: CF | Tags: | Read Count: 724
pavzi.com 说:
2024年1月21日 20:11

Pavzi.com provides all the news about Gadgets, the Economy, Technology, Business, Finance and many more. The main concept or our aim behind this website has been the will to provide resources with full information on each topic which can be accessed through the Internet. To ensure that every reader gets what is important and worthy about the topic they search and link to hear from us. pavzi.com Our site is a multiple Niche or category website which will ensure to provide information and resources on each and every topic. Some of the evergreen topics you will see on our website are Career, Job Recruitment, Educational, Technology, Reviews and others. We are targeting mostly so it is true that Tech, Finance, and Product Reviews. The only reason we have started this website is to make this site the need for your daily search use.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter

Host by is-Programmer.com | Power by Chito 1.3.3 beta | Theme: Aeros 2.0 by TheBuckmaker.com