zoukankan      html  css  js  c++  java
  • hdu 2817 A sequence of numbers(快速幂)

     

    Problem 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
    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
    Output one line for each test case, that is, the K-th number module (%) 200907.
     
    Sample Input
    2 1 2 3 5 1 2 4 5
     
    Sample Output
    5 16
     
    Source
     

    等比数列或等差数列。。。

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 #include<cmath>
     5 #include<stdlib.h>
     6 #include<algorithm>
     7 #include<queue>
     8 #include<map>
     9 using namespace std;
    10 #define MOD 200907
    11 #define ll long long
    12 ll pow_mod(ll a,ll n)
    13 {
    14     if(n==0)
    15        return 1%MOD;
    16     ll tt=pow_mod(a,n>>1);
    17     ll ans=tt*tt%MOD;
    18     if(n&1)
    19       ans=ans*a%MOD;
    20     return ans;
    21 }
    22 int main()
    23 {
    24     int t;
    25     scanf("%d",&t);
    26     while(t--)
    27     {
    28         ll a,b,c,k;
    29         scanf("%I64d%I64d%I64d%I64d",&a,&b,&c,&k);
    30         if(a==b && b==c)
    31         {
    32             printf("%I64d
    ",a%MOD);
    33             continue;
    34         }
    35         if(k==1)
    36         {
    37             printf("%I64d
    ",a%MOD);
    38             continue;
    39         }
    40         if(k==2)
    41         {
    42             printf("%I64d
    ",b%MOD);
    43             continue;
    44         }
    45         if(k==3)
    46         {
    47             printf("%I64d
    ",c%MOD);
    48             continue;
    49         }
    50         ll cnt=b-a;
    51         if(c-b==cnt)
    52         {
    53             ll ans=a+(k-1)*cnt;
    54             printf("%I64d
    ",ans%MOD);
    55         }
    56         else 
    57         {
    58             ll q=b/a;
    59             printf("%I64d
    ",a*pow_mod(q,k-1)%MOD);
    60         }
    61     }
    62     return 0;
    63 }
    View Code
  • 相关阅读:
    使用postman做接口测试(三)
    使用postman做接口测试(二)
    使用postman做接口测试(一)
    RobotFramework安装扩展库包autoitlibrary(四)
    RobotFramework安装扩展库包Selenium2Library(三)
    记录.gitattributes 设置合并时使用本地文件无效的解决方案
    golang 踩坑日记
    linux常用命令记录
    vim配置文件
    mysql case when记录
  • 原文地址:https://www.cnblogs.com/UniqueColor/p/4743772.html
Copyright © 2011-2022 走看看