#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll arr[100009];
int main()
{
ll i,j,k,l,m,n,test,K,C;
cin>>test;
for(k=1;k<=test;k++)
{
cin>>K>>C;
cin>>n>>arr[0];
ll sum=arr[0];
for(i=1;i<n;i++)
{
arr[i]=(K*arr[i-1]+C)%1000007;
sum+=arr[i];
}
sort(arr,arr+n);
ll S=0,prev_sum=0;
for(i=0;i<n;i++)
{
prev_sum+=arr[i];
ll tmp=((n-i-1)*arr[i])-(sum-prev_sum);
if(tmp<0)
tmp*=(-1);
S+=tmp;
}
cout<<"Case "<<k<<": "<<S<<endl;
}
return 0;
}
using namespace std;
typedef long long ll;
ll arr[100009];
int main()
{
ll i,j,k,l,m,n,test,K,C;
cin>>test;
for(k=1;k<=test;k++)
{
cin>>K>>C;
cin>>n>>arr[0];
ll sum=arr[0];
for(i=1;i<n;i++)
{
arr[i]=(K*arr[i-1]+C)%1000007;
sum+=arr[i];
}
sort(arr,arr+n);
ll S=0,prev_sum=0;
for(i=0;i<n;i++)
{
prev_sum+=arr[i];
ll tmp=((n-i-1)*arr[i])-(sum-prev_sum);
if(tmp<0)
tmp*=(-1);
S+=tmp;
}
cout<<"Case "<<k<<": "<<S<<endl;
}
return 0;
}
No comments:
Post a Comment