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
  • 相关阅读:
    Objective-C-使用NSMutableURLRequest发送POST请求,使用NSJSONSerialization解析JSON字符串
    js showModalDialog打开新的页面给原页面传值问题
    svn2git使用小记
    模拟等待事件row lock waits
    URAL 1994 The Emperor's plan 求组合数 大数用log+exp处理
    struts总结
    URAL 1992 CVS 链表
    android游戏物理引擎开发——粒子系统(三)
    状态模式与上机
    OpenCV——凸包
  • 原文地址:https://www.cnblogs.com/UniqueColor/p/4743772.html
Copyright © 2011-2022 走看看