hdu2817 2010.2.25
1. 等差数列和等比数列的英文单词没认出来,对题意理解错误。
2. 学到了快速幂,这道题目,如果不用快速幂的话,一定会超时的。
#include <stdio.h>
#include <string.h>
__int64 ans,a,b,c,n;
__int64 x[120],lx;
void main()
{
int k,t;
scanf("%d",&t);
for(k=1;k<=t;k++)
{
scanf("%I64d %I64d %I64d %I64d",&a,&b,&c,&n);
if (b-a==c-b)
printf("%I64d\n",((n-1)%200907*((b-a)%200907)+a%200907)%200907);
else
{
__int64 r,i,m;
r=b/a;
ans=1;
m=n-1;
for(i=1;m>0;i++)
{
x[i]=m%2;
m/=2;
}
for(i--;i>=1;i--)
{
ans=ans*ans%200907;
if (x[i]>0)
ans=ans*r%200907;
}
printf("%I64d\n",(ans*(a%200907))%200907);
}
}
}
A sequence of numbers
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 403 Accepted Submission(s): 122
Problem Description
Xinlv wrote some sequences on the paper along time ago, they might be arithmetic orgeometric sequences. The numbers are not very clear now, and only thefirst three numbers of each sequence are recognizable. Xinlv wants to know somenumbers 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 containfour integers. The first three indicating the first three numbers of thesequence, and the last one is K, indicating that we want to know the K-thnumbers of the sequence.
You can assume 0 < K <= 10^9, and theother three numbers are in the range [0, 2^63). All the numbers of thesequences are integers. And the sequences are non-decreasing.
Output
Output one line for each test case, thatis, the K-th number module (%) 200907.
Sample Input
2
1 2 3 5
1 2 4 5
Sample Output
5
16
Source
2009 Multi-University Training Contest 1 -Host by TJU
Recommend
gaojie