HDU 2187 A sequence of numbers
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2817
题意: 给定三个数,判断是等差数列还是等比数列,然后输出第k项.
做法:直接判断即可
#include <iostream> #include <cstdio> #include <algorithm> #include <vector> #include <set> #include <queue> #include <set> #include <map> #include <cstring> #include <functional> #include <cmath> typedef unsigned long long ll; ll mod = 200907; using namespace std; ll mul(ll a,ll b){ return ((a%mod)*(b%mod))%mod; } ll pw(ll a,ll n){ if(n==1) return a%mod; ll tmp = pw(a,n/2)%mod; if(n&1) return (tmp*tmp*a)%mod; else return (tmp*tmp)%mod; } int main(){ ios::sync_with_stdio(0); int t; cin>>t; while(t--){ ll a,b,c,d; cin>>a>>b>>c>>d; if(b-a == c-b){ ll dt = b-a; ll ans = a+mul(dt,d-1); cout<<ans%mod<<endl; }else{ ll p = b / a; ll ans = a*pw(p,d-1); cout<<ans%mod<<endl; } } }