Of course, his speeding caught the attention of the traffic police. Police record NNpositions of Ruins without time mark, the only thing they know is every position is recorded at an integer time point and Ruins started at 00.
Now they want to know the minimum time that Ruins used to pass the last position.
Every test case begins with an integers NN, which is the number of the recorded positions.
The second line contains NN numbers a1a1, a2a2, ⋯⋯, aNaN, indicating the recorded positions.
Limits
1≤T≤1001≤T≤100
1≤N≤1051≤N≤105
0<ai≤1090<ai≤109
ai<ai+1ai<ai+1OutputFor every test case, you should output 'Case #x: y', where x indicates the case number and counts from 1 and y is the minimum time.Sample Input
1 3 6 11 21Sample Output
Case #1: 4
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cstdio>
using namespace std;
/*void swapping(long long *a,long long *b)
{
long long t=*a;
*a=*b;
*b=t;
}*/
long long a[200000];
int main()
{
int T;
scanf("%d",&T);
for(int k=1;k<=T;k++)
{
long long fenzi,fenmu;
int n;
scanf("%d",&n);
a[0]=0;
long long ans=0;
for(int i=1;i<=n;i++)
{
scanf("%lld",&a[i]);
}
fenzi=a[n]-a[n-1];
fenmu=1;
for(int i=n;i>0;i--)
{
if(((a[i]-a[i-1])*fenmu)%fenzi==0)
{
ans=ans+(a[i]-a[i-1])*fenmu/fenzi;
}
else
{
int w=(a[i]-a[i-1])*fenmu/fenzi;
ans=ans+(w+1);
fenzi=(a[i]-a[i-1]);
fenmu=w+1;
}
}
printf("Case #%d: %lld\n",k,ans);
}
return 0;
}