Hdu 2817 A sequence of numbers (quick power)

Source: Internet
Author: User

During the first small competition, I couldn't even understand the question. Later I heard the teacher explain it and understood the question, but I still couldn't! Success !!!

#¥ # ¥ # % ¥ % ...... ¥ % ...... &...... & * () & * (% ...... & Amp; % ¥ %

Why! Because at that time, I would not be able to quickly find the power, right, that is, to quickly find the power. The value of this question is to teach me to learn this!

&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

Question: Let's give you the first three numbers of a sequence. This sequence is either an equal-difference sequence or an equal-ratio sequence. Let's give you an n and find the nth item of the sequence (haha, let's do it !)

**************************************** **************************************** **************************************** ***************************

#include<stdio.h>#define N 200907__int64 pow(__int64 q,__int64 n){__int64 ans=1;while(n){if(n&1)ans=ans%N*(q%N)%N;n/=2;q=q%N*(q%N)%N;}return ans;}int main(){__int64 t,a,b,c,q,d,n,ans;scanf("%I64d",&t);while(t--){scanf("%I64d%I64d%I64d%I64d",&a,&b,&c,&n);if(2*b==a+c){d=b-a;ans=(a+(n-1)*d%N)%N;}else{q=b/a;ans=a*pow(q,n-1)%N;}printf("%I64d\n",ans);}return 0;} 

 

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.