[2020.10.26 SSL Simulation Tournament T1] Magic Tribe [Number Theory Inverse Element]

table of Contents:

T1:魔法部落
T2:圆盘
T3:棋盘行走
T4:走方格

A set of questions that are not difficult as a whole but require details

T1 :

Insert picture description here
Insert picture description here

analysis:

It can be seen that this is a common ratio of 3 3The geometric sequence of 3 is
known to be the firstnnof the geometric sequenceThe sum of n items is: common ratioqqq^ ( n + 1 ) / ( (n+1)/( (n+1 ) / ( Common ratioq − 1) q-1)q1 )
That is:3 33^ ( n + 1 ) / 2 (n+1)/2 (n+1 ) / 2
So this quick power+ mod + mod+ m o d can welcome60 pts 60pts6 0 p t s andwa waw a some point
why?
Becausex / yx/yx/y m o d mod m o d may appear negative, so it needs to be solved by inverse element.
Finally:qqq^ ( n + 1 ) / ( q − 1 ) m o d ( 1 e 9 + 7 ) (n+1)/(q-1)mod(1e9+7) (n+1)/(q1 ) m o d ( 1 e 9+7)
= q =q =q ^(n + 1) ∗ (1 e 9 + 7 + 1) / 2 (n + 1) * (1e9 + 7 + 1) / 2(n+1)(1e9+7+1 ) / 2 mod(1e 9 + 7) (1e9 + 7)(1e9+7)
= q =q =q^ ( n + 1 ) ∗ 5 e 8 + 4 (n+1)*5e8+4 (n+1)5 e 8+4 mod(1e 9 + 7) (1e9 + 7)(1e9+7)

CODE:

#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
const long long p=1e9+7;
const long long s=5e8+4;
ll n,ans,qwq=1;
void ksm(ll n)
{
    
    
	long long tmp=3;
    while(n){
    
    
        if(n&1){
    
    
            qwq=(qwq*tmp)%p;
        }
        tmp=(tmp*tmp)%p;
        n>>=1;
    }
}
int main(){
    
    
	scanf("%lld",&n);
	ksm(n+1);
	ans=(qwq-1)*s%p;
	printf("%lld",ans);
	return 0;
} 

Guess you like

Origin blog.csdn.net/dgssl_xhy/article/details/109298126