HBMY=1875: A sequence of numbers

来源:互联网 发布:unity3d下载安装教程 编辑:程序博客网 时间:2024/06/03 18:02

1875: A sequence of numbers


Time Limit: 1 Seconds   Memory Limit: 32 Mbyte
Total Submissions: 9    Accepted: 3
[Submit]   [Statistic]   [discuss]   [Go Back]

题目描述

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.

输入描述

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 is K, 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 one line for each test case, that is, the K-th number module (%) 200907.

输入样例

21 3 5 82 4 8 7

输出样例

15128

提示

来源or类型

入门题-数学



AC 代码:

#include<iostream>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;


int main()
{
   long long T;
   long long a,b,c,d,i;
   cin>>T;
   while(T--)
   {
       cin>>a>>b>>c>>d;
        if(a==b && b==c )
        {
            cout<<a%200907<<endl;
            continue;
        }
       if(b-a==c-b)
       {
           long long  s=b-a;
            cout<<a%200907+((((d-1)%200907)*(s%200907))%200907)%200907<<endl;
       }
      else
       {
           long long l=(b/a)%200907;
           long long temp=1;
            d--;
            a=a%200907;
            while(d)    //关键的地方,才开始因为没有想到这里,直接用的是for语句,不是WA,就是超时,然后换这个思路才AC,现在还是不明白为什么for不行,很尴尬的;
            {
                  if(d%2==1)
                  {
                    temp=temp*l;
                    temp%=200907;
                  }
                l=(l*l)%200907;
                d/=2;
            }
           long long  sum=(a*temp)%200907;
           cout<<sum<<endl;
       }
   }


    return 0;
}

原创粉丝点击