• hdu2817 A sequence of numbers(等差等比数列)


     1 #include<stdio.h>
     2 #define e 200907
     3 int main()
     4 {
     5     __int64 a,b,c,n,ans;
     6     int t;
     7     scanf("%d",&t);
     8     while(t--)
     9     {
    10         scanf("%I64d%I64d%I64d%I64d",&a,&b,&c,&n);
    11         if(n==1)
    12         {
    13             printf("%I64d
    ",a%e);
    14             continue;
    15         }
    16         if(b-a==c-b)
    17         {
    18             ans=(a%e+((n-1)%e*(b-a)%e)%e)%e;
    19         }
    20         else
    21         {
    22             __int64 d;
    23             d=(b/a)%e;
    24             a=a%e;
    25             n--;
    26             __int64 x=n;
    27             __int64 tt=2;
    28             __int64 temp=d;
    29             while(x>0)
    30             {
    31                 while(tt<x)
    32                 {
    33                     temp=(temp*temp)%e;
    34                     tt=tt*2;
    35                 }
    36                 a=(a*temp)%e;
    37                 x-=tt/2;
    38                 tt=2;
    39                 temp=d;
    40             }
    41             ans=a;
    42         }
    43         printf("%I64d
    ",ans);
    44     }
    45     return 0;
    46 }
    View Code
     1 #include<stdio.h>
     2 #define e 200907
     3 __int64 fun(__int64 a,__int64 b)
     4 {
     5     __int64 temp=1;
     6     a=a%e;
     7     while(b>0)
     8     {
     9         if(b%2!=0)
    10             temp=(a*temp)%e;
    11         a=(a*a)%e;
    12         b=b/2;
    13         
    14     }
    15     return temp;
    16 }
    17 int main()
    18 {
    19     __int64 a,b,c,n,ans;
    20     int t;
    21     scanf("%d",&t);
    22     while(t--)
    23     {
    24         scanf("%I64d%I64d%I64d%I64d",&a,&b,&c,&n);
    25         if(b-a==c-b)
    26         {
    27             ans=(a%e+((n-1)%e*(b-a)%e)%e)%e;
    28         }
    29         else
    30         {
    31             n--;
    32             ans=(a%e)*fun(b/a,n);
    33         }
    34         printf("%I64d
    ",ans%e);
    35     }
    36     return 0;
    37 }
    View Code
  • 相关阅读:
    高斯消元
    UVa12103
    UVa10294
    UVa11762
    牛客网算法工程师能力评估
    华为研发工程师编程题
    网易2017春招笔试真题编程题集合
    2017网易有道内推编程题
    2017网易雷火实习生招聘编程题
    数组---面试知识点整理
  • 原文地址:https://www.cnblogs.com/zlyblog/p/3190582.html
Copyright © 2020-2023  润新知