2020 Niu Ke NOIP pre-match training camp-increase the number of girls in the T1 Niu Banxian group (the third game)

Niu Banxian has three sisters, their attribute values ​​are AAA, B B B, C C C . These three girls are telepathic, and when one person's attribute value changes, the other person's attribute value also changes.
The law of change is as follows: Suppose the attribute value of the first girl isAAA , the attribute value of the second girl isBBB , the attribute value of the third girl isCCC

  • If A + B ≤ C A+B≤CA+BC then the attribute value of the first girl becomes2 A 2A2 A , the attribute value of the second girl becomes2 B 2B2 B , the attribute value of the third girl becomesC − A − BC−A−BCAB
  • Otherwise set AAA, B B The smaller attribute value in B isWWW P = m i n ( ⌊ C / 2 ⌋ , W − 1 ) P=min(\lfloor C/2\rfloor,W-1) P=m i n ( C / 2 ,W1 ) . Then the attribute value of the first girl becomesA − PA−PA P , the attribute value of the second girl becomesB + P − C B+PCB+PC , the attribute value of the third girl becomes2 C 2C2 C .
    Niu Banxian wants to know that the third girl passed byKKThe attribute value after K changes. Because Niu Banxian wants to talk about life with his sister, he left this question to you.
    Link: https://ac.nowcoder.com/acm/contest/7609/A
    Source: Niuke

Simplify decently given two numbers a (a = A + B + C) a\ (a=A+B+C)a (a=A+B+C ) andb (b = C) b\ (b=C)b (b=C)
b > a b>a b>a b = b − a   ,   a = 2 ⋅ a b=b-a\ ,\ a=2\cdot a b=ba , a=2a
否则 b = 2 ⋅ b   ,   a = a − b b=2\cdot b\ ,\ a=a-b b=2b , a=ab

Discussing the value classification of b can conclude that
ans = (2 k ⋅ b) mod (a + b) ans=(2^k \cdot b)mod(a+b)a n s=(2kb)mod(a+b)

#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
ull t,u,v,mod,b,k,ans;
inline ull ksm(ull x,ull y){
    
    
	ull res=1;
	while(y){
    
    
		if(y&1)res=res*x%mod;
		x=x*x%mod; y>>=1;
	} 
	return res;
}
int main(){
    
    
	scanf("%llu",&t);
	while(t--){
    
    
		scanf("%llu %llu %llu %llu",&u,&v,&b,&k);
		mod=u+v+b;
		ans=ksm(2,k)*b%mod;
		printf("%llu\n",ans);
	}
}

Guess you like

Origin blog.csdn.net/RA100FDM/article/details/109231398