A sequence of numbers (quick power)

Source: Internet
Author: User

A sequence of numbers (quick power)

Description

Xinlv wrote some sequences on the paper a long time ago, they might be arithmetic or geometric sequences. the numbers are not very clear now, and only the first three numbers of each sequence are recognizable. xinlv wants to know some numbers in these sequences, and he needs your help.

Input requirements

The first line contains an integer N, indicting that there are N sequences. each of the following N lines contain four integers. the first three indicating the first three numbers of the sequence, and the last one isK, Indicating that we want to know the K-th numbers of the sequence.

You can assume 0 <K <= 10 ^ 9, and the other three numbers are in the range [0, 2 ^ 63 ). all the numbers of the sequences are integers. and the sequences are non-decreasing.

Output requirements

Output one line for each test case, that is, the K-th numberModule (%) 200907.

Assume that
21 2 3 51 2 4 5
Output
516
The question is very simple, that is, to give you a sequence of the first three items, the sequence is not an equality or an equality ratio, let you calculate the K more than 200907.


The code for quick idempotence is

int fastpow(int a,int b){int r=1,base=a;while(b!=0){if(b&1)r*=base;base*=base;b>>=1;}return r;}

Ac code

#include
 
  #include#include 
  
   #include
   
    #include
    
     #include 
     
      #include
      
       #include
       
        #include 
        
         #include
         using namespace std;int MOD=200907;long long fastpow(long long q,long long n){long long r=1;while(n){if(n&1)r=r%MOD*(q%MOD)%MOD;q=q%MOD*(q%MOD)%MOD;n>>=1;}return r;}void solve();int main(){solve();return 0;}void solve(){ long long t,a1,a2,a3,n,d,ans,q;cin>>t;while(t--){cin>>a1>>a2>>a3>>n;if(a2*2==a1+a3){d=a2-a1;ans=(a1+(n-1)*d%MOD)%MOD;}else{q=a2/a1;ans=a1*fastpow(q,n-1)%MOD;}cout<






Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.