http://acm.hdu.edu.cn/showproblem.php?pid=2817

__int64 pow_mod (__int64 a, __int64 n, __int64 m)快速幂取模函数。

A sequence of numbers

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4047    Accepted Submission(s):
1243

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
 
#include<stdio.h>
#include<string.h>
#define MOD 200907
__int64 pow_mod (__int64 a, __int64 n, __int64 m)
{
if(n==)
return %m;
if(n==)
return a%m;
__int64 x=pow_mod(a,n/,m);
__int64 ans=x*x%m;
if(n%==) ans=ans*a%m; return ans;
} int main()
{
double a,b,c;
int t;
int k;
scanf("%d",&t);
while(t--)
{
scanf("%lf%lf%lf%d",&a,&b,&c,&k);
if(a+c==*b)
{
__int64 a1=(__int64 )a;
__int64 d=(__int64 )(b-a);
int ans=(a1%MOD+((k-)%MOD)*(d%MOD))%MOD;
printf("%d\n",ans);
}
else
{
__int64 a1=(__int64)a;
__int64 t1=(__int64)(a1%MOD);
double q1=(b/a);
__int64 q2=(__int64)q1;
__int64 q=(__int64)q2;
__int64 tmp=pow_mod(q,k-,MOD);
int ans=(t1*tmp)%MOD;
printf("%d\n",ans);
}
}
return ;
}

HDU 2817 A sequence of numbers的更多相关文章

  1. HDU 2817 A sequence of numbers 整数快速幂

    A sequence of numbers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  2. hdu 2817 A sequence of numbers(快速幂)

    Problem Description Xinlv wrote some sequences on the paper a long time ago, they might be arithmeti ...

  3. hdu 2817 A sequence of numbers(快速幂取余)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2817 题目大意:给出三个数,来判断是等差还是等比数列,再输入一个n,来计算第n个数的值. #inclu ...

  4. hdoj 2817 A sequence of numbers【快速幂】

    A sequence of numbers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  5. HDU 2187 A sequence of numbers

    题目连接  http://acm.hdu.edu.cn/showproblem.php?pid=2817 题意: 给定三个数,判断是等差数列还是等比数列,然后输出第k项. 做法:直接判断即可 #inc ...

  6. 杭电 2817 A sequence of numbers【快速幂取模】

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2817 解题思路:arithmetic or geometric sequences 是等差数列和等比数 ...

  7. HDU 1711 Number Sequence(数列)

    HDU 1711 Number Sequence(数列) Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Ja ...

  8. HDU 1711 Number Sequence (字符串匹配,KMP算法)

    HDU 1711 Number Sequence (字符串匹配,KMP算法) Description Given two sequences of numbers : a1, a2, ...... , ...

  9. HDU 5860 Death Sequence(死亡序列)

    p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...

随机推荐

  1. free -m

    free -m total used free shared buffers cached Mem: 7760 1572   6187          0              9       ...

  2. C# 创建XML文档

    有些时候我们需要生成一个xml文档作为数据交换的容器.当然我们用拼接字符串的方法来进行构建xml,但是这种方法虽然简单有效,但是如果xml文档结构过于复杂,拼接字符串会让人眼花缭乱.这时候就需要C#给 ...

  3. 细说 ASP.NET Cache 及其高级用法

    许多做过程序性能优化的人,或者关注过程程序性能的人,应该都使用过各类缓存技术. 而我今天所说的Cache是专指ASP.NET的Cache,我们可以使用HttpRuntime.Cache访问到的那个Ca ...

  4. 【BZOJ】1046 : [HAOI2007]上升序列

    1046: [HAOI2007]上升序列 题意:给定S={a1,a2,a3,…,an}问是否存在P={ax1,ax2,ax3,…,axm},满足(x1 < x2 < … < xm)且 ...

  5. ubuntu 12.04 安装 nginx+php+mysql web服务器

    Nginx 是一个轻量级,以占用系统资源少,运行效率而成为web服务器的后起之秀,国内现在很多大型网站都以使用nginx,包括腾讯.新浪等大型信息网站,还有淘宝网站使用的是nginx二次开发的web服 ...

  6. entity framework in mysql

    To start using Entity Framework 6 and Visual Studio 2013 is necessary to install MySQL for Visual St ...

  7. Adapting to views using css or js

    using css @media screen and (-ms-view-state: fullscreen-landscape) { } @media screen and (-ms-view-s ...

  8. JAVA入门第二季(mooc-笔记)

    相关信息 /** * @subject <学习与创业>作业1 * @author 信管1142班 201411671210 赖俊杰 * @className <JAVA入门第二季&g ...

  9. Python属性、方法和类管理系列之----__slots__属性

    一句话说明 __slots__是用来限制实例的属性的,__slots__可以规定实例是否应该有__dict__属性:__slots__不能限制类的属性. 只有__slots__列表内的这些变量名可赋值 ...

  10. 上传项目到Github

    1.使用根工具(均是图形化的界面) TortoiseGit-1.8.12.0-32bit GitExtensions-2.48.05-SetupComplete 2.大致步骤 首先,你需要一个Gith ...