prob_desc_description stringlengths 63 3.8k | prob_desc_output_spec stringlengths 17 1.47k ⌀ | lang_cluster stringclasses 2 values | src_uid stringlengths 32 32 | code_uid stringlengths 32 32 | lang stringclasses 7 values | prob_desc_output_to stringclasses 3 values | prob_desc_memory_limit stringclasses 19 values | file_name stringclasses 111 values | tags listlengths 0 11 | prob_desc_created_at stringlengths 10 10 | prob_desc_sample_inputs stringlengths 2 802 | prob_desc_notes stringlengths 4 3k ⌀ | exec_outcome stringclasses 1 value | difficulty int64 -1 3.5k ⌀ | prob_desc_input_from stringclasses 3 values | prob_desc_time_limit stringclasses 27 values | prob_desc_input_spec stringlengths 28 2.42k ⌀ | prob_desc_sample_outputs stringlengths 2 796 | source_code stringlengths 42 65.5k | hidden_unit_tests stringclasses 1 value |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
You are given two matrices $$$A$$$ and $$$B$$$. Each matrix contains exactly $$$n$$$ rows and $$$m$$$ columns. Each element of $$$A$$$ is either $$$0$$$ or $$$1$$$; each element of $$$B$$$ is initially $$$0$$$.You may perform some operations with matrix $$$B$$$. During each operation, you choose any submatrix of $$$B$$$ having size $$$2 \times 2$$$, and replace every element in the chosen submatrix with $$$1$$$. In other words, you choose two integers $$$x$$$ and $$$y$$$ such that $$$1 \le x < n$$$ and $$$1 \le y < m$$$, and then set $$$B_{x, y}$$$, $$$B_{x, y + 1}$$$, $$$B_{x + 1, y}$$$ and $$$B_{x + 1, y + 1}$$$ to $$$1$$$.Your goal is to make matrix $$$B$$$ equal to matrix $$$A$$$. Two matrices $$$A$$$ and $$$B$$$ are equal if and only if every element of matrix $$$A$$$ is equal to the corresponding element of matrix $$$B$$$.Is it possible to make these matrices equal? If it is, you have to come up with a sequence of operations that makes $$$B$$$ equal to $$$A$$$. Note that you don't have to minimize the number of operations. | If it is impossible to make $$$B$$$ equal to $$$A$$$, print one integer $$$-1$$$. Otherwise, print any sequence of operations that transforms $$$B$$$ into $$$A$$$ in the following format: the first line should contain one integer $$$k$$$ — the number of operations, and then $$$k$$$ lines should follow, each line containing two integers $$$x$$$ and $$$y$$$ for the corresponding operation (set $$$B_{x, y}$$$, $$$B_{x, y + 1}$$$, $$$B_{x + 1, y}$$$ and $$$B_{x + 1, y + 1}$$$ to $$$1$$$). The condition $$$0 \le k \le 2500$$$ should hold. | C | ad641a44ecaf78ca253b199f3d40ef96 | e30caef57e11693c50187745a42232ce | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"constructive algorithms",
"implementation",
"greedy"
] | 1566484500 | ["3 3\n1 1 1\n1 1 1\n0 1 1", "3 3\n1 0 1\n1 0 1\n0 0 0", "3 2\n0 0\n0 0\n0 0"] | NoteThe sequence of operations in the first example: $$$\begin{matrix} 0 & 0 & 0 & & 1 & 1 & 0 & & 1 & 1 & 1 & & 1 & 1 & 1 \\ 0 & 0 & 0 & \rightarrow & 1 & 1 & 0 & \rightarrow & 1 & 1 & 1 & \rightarrow & 1 & 1 & 1 \\ 0 & 0 & 0 & & 0 & 0 & 0 & & 0 & 0 & 0 & & 0 & 1 & 1 \end{matrix}$$$ | PASSED | 1,200 | standard input | 1 second | The first line contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 50$$$). Then $$$n$$$ lines follow, each containing $$$m$$$ integers. The $$$j$$$-th integer in the $$$i$$$-th line is $$$A_{i, j}$$$. Each integer is either $$$0$$$ or $$$1$$$. | ["3\n1 1\n1 2\n2 2", "-1", "0"] | #include<stdio.h>
int main()
{
int a[100][100], b[100][100], i, j, n, m, c=0, k[100001], l[100001], d=0;
scanf("%d %d", &n, &m);
for(i=1; i<=n; i++)
{
for(j=1; j<=m; j++)
{
scanf("%d", &a[i][j]);
}
}
for(i=1; i<n; i++)
{
for(j=1; j<m; j++)
{
if(a[i][j]==1 && a[i][j+1]==1 && a[i+1][j]==1 && a[i+1][j+1]==1)
{
b[i][j] = b[i][j+1] = b[i+1][j] = b[i+1][j+1] = 1;
c++;
k[c] = i;
l[c] = j;
}
}
}
for(i=1; i<=n; i++)
{
for(j=1; j<=m; j++)
{
if(a[i][j]==b[i][j])
{
d++;
}
}
}
if(d!=m*n)
{
printf("-1\n");
}
else
{
printf("%d\n",c);
for(i=1; i<=c; i++)
{
printf("%d %d\n",k[i],l[i]);
}
}
return 0;
}
| |
You are given two matrices $$$A$$$ and $$$B$$$. Each matrix contains exactly $$$n$$$ rows and $$$m$$$ columns. Each element of $$$A$$$ is either $$$0$$$ or $$$1$$$; each element of $$$B$$$ is initially $$$0$$$.You may perform some operations with matrix $$$B$$$. During each operation, you choose any submatrix of $$$B$$$ having size $$$2 \times 2$$$, and replace every element in the chosen submatrix with $$$1$$$. In other words, you choose two integers $$$x$$$ and $$$y$$$ such that $$$1 \le x < n$$$ and $$$1 \le y < m$$$, and then set $$$B_{x, y}$$$, $$$B_{x, y + 1}$$$, $$$B_{x + 1, y}$$$ and $$$B_{x + 1, y + 1}$$$ to $$$1$$$.Your goal is to make matrix $$$B$$$ equal to matrix $$$A$$$. Two matrices $$$A$$$ and $$$B$$$ are equal if and only if every element of matrix $$$A$$$ is equal to the corresponding element of matrix $$$B$$$.Is it possible to make these matrices equal? If it is, you have to come up with a sequence of operations that makes $$$B$$$ equal to $$$A$$$. Note that you don't have to minimize the number of operations. | If it is impossible to make $$$B$$$ equal to $$$A$$$, print one integer $$$-1$$$. Otherwise, print any sequence of operations that transforms $$$B$$$ into $$$A$$$ in the following format: the first line should contain one integer $$$k$$$ — the number of operations, and then $$$k$$$ lines should follow, each line containing two integers $$$x$$$ and $$$y$$$ for the corresponding operation (set $$$B_{x, y}$$$, $$$B_{x, y + 1}$$$, $$$B_{x + 1, y}$$$ and $$$B_{x + 1, y + 1}$$$ to $$$1$$$). The condition $$$0 \le k \le 2500$$$ should hold. | C | ad641a44ecaf78ca253b199f3d40ef96 | b80fa895eff108ad44c71d119cf4acd4 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"constructive algorithms",
"implementation",
"greedy"
] | 1566484500 | ["3 3\n1 1 1\n1 1 1\n0 1 1", "3 3\n1 0 1\n1 0 1\n0 0 0", "3 2\n0 0\n0 0\n0 0"] | NoteThe sequence of operations in the first example: $$$\begin{matrix} 0 & 0 & 0 & & 1 & 1 & 0 & & 1 & 1 & 1 & & 1 & 1 & 1 \\ 0 & 0 & 0 & \rightarrow & 1 & 1 & 0 & \rightarrow & 1 & 1 & 1 & \rightarrow & 1 & 1 & 1 \\ 0 & 0 & 0 & & 0 & 0 & 0 & & 0 & 0 & 0 & & 0 & 1 & 1 \end{matrix}$$$ | PASSED | 1,200 | standard input | 1 second | The first line contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 50$$$). Then $$$n$$$ lines follow, each containing $$$m$$$ integers. The $$$j$$$-th integer in the $$$i$$$-th line is $$$A_{i, j}$$$. Each integer is either $$$0$$$ or $$$1$$$. | ["3\n1 1\n1 2\n2 2", "-1", "0"] | #include<stdio.h>
int main()
{
int a[100][100], b[100][100], i, j, n, m, c=0, k[100001], l[100001], d=0;
scanf("%d %d", &n, &m);
for(i=0; i<n; i++)
{
for(j=0; j<m; j++)
{
scanf("%d", &a[i][j]);
}
}
for(i=0; i<n-1; i++)
{
for(j=0; j<m-1; j++)
{
if(a[i][j]==1 && a[i][j+1]==1 && a[i+1][j]==1 && a[i+1][j+1]==1)
{
b[i][j] = b[i][j+1] = b[i+1][j] = b[i+1][j+1] = 1;
c++;
k[c] = i;
l[c] = j;
}
}
}
for(i=0; i<n; i++)
{
for(j=0; j<m; j++)
{
if(a[i][j]==b[i][j])
{
d++;
}
}
}
if(d!=m*n)
{
printf("-1\n");
}
else
{
printf("%d\n",c);
for(i=1; i<=c; i++)
{
printf("%d %d\n",k[i]+1,l[i]+1);
}
}
return 0;
}
| |
Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.You've got string s = s1s2... sn (n is the length of the string), consisting only of characters "." and "#" and m queries. Each query is described by a pair of integers li, ri (1 ≤ li < ri ≤ n). The answer to the query li, ri is the number of such integers i (li ≤ i < ri), that si = si + 1.Ilya the Lion wants to help his friends but is there anyone to help him? Help Ilya, solve the problem. | Print m integers — the answers to the queries in the order in which they are given in the input. | C | b30e09449309b999473e4be6643d68cd | 410d1e49bafbf6064f43d98dbbc8556d | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"dp",
"implementation"
] | 1369927800 | ["......\n4\n3 4\n2 3\n1 6\n2 6", "#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line contains string s of length n (2 ≤ n ≤ 105). It is guaranteed that the given string only consists of characters "." and "#". The next line contains integer m (1 ≤ m ≤ 105) — the number of queries. Each of the next m lines contains the description of the corresponding query. The i-th line contains integers li, ri (1 ≤ li < ri ≤ n). | ["1\n1\n5\n4", "1\n1\n2\n2\n0"] | #include <stdio.h>
#include <stdio.h>
#define N 300005
int main(int argc, char *argv[])
{
char ch[N];
int n,i,a[N]={0},pref[N]={0},sum=0,l,r;
scanf("%s",ch);
scanf("%d",&n);
for(i=0;i<strlen(ch)-1;i++)
if(ch[i]==ch[i+1]){
a[i]++;
}
for(i=1;i<=strlen(ch);i++){
sum+=a[i-1];
pref[i]=sum;
// printf("%d\n",pref[i]);
}
for(i=0;i<n;i++){
scanf("%d%d",&l,&r);
printf("%d\n",pref[r-1]-pref[l-1]);
}
} | |
Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.You've got string s = s1s2... sn (n is the length of the string), consisting only of characters "." and "#" and m queries. Each query is described by a pair of integers li, ri (1 ≤ li < ri ≤ n). The answer to the query li, ri is the number of such integers i (li ≤ i < ri), that si = si + 1.Ilya the Lion wants to help his friends but is there anyone to help him? Help Ilya, solve the problem. | Print m integers — the answers to the queries in the order in which they are given in the input. | C | b30e09449309b999473e4be6643d68cd | 842e377179638cef84e32586d9068171 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"dp",
"implementation"
] | 1369927800 | ["......\n4\n3 4\n2 3\n1 6\n2 6", "#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line contains string s of length n (2 ≤ n ≤ 105). It is guaranteed that the given string only consists of characters "." and "#". The next line contains integer m (1 ≤ m ≤ 105) — the number of queries. Each of the next m lines contains the description of the corresponding query. The i-th line contains integers li, ri (1 ≤ li < ri ≤ n). | ["1\n1\n5\n4", "1\n1\n2\n2\n0"] | #include<stdio.h>
#include<string.h>
int main()
{
char x[100001];
gets(x);
int t,n=strlen(x),a,b,i,y[100001]={},sum=0;
for(i=0;i<n-1;i++)
{ y[i+1]=sum;
if(x[i]==x[i+1]) {y[i+1]++; sum=y[i+1]; }}
scanf("%d",&t);
while(t--)
{
int c=0;
scanf("%d %d",&a,&b);
printf("%d\n",y[b-1]-y[a-1]);
}
}
| |
Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.You've got string s = s1s2... sn (n is the length of the string), consisting only of characters "." and "#" and m queries. Each query is described by a pair of integers li, ri (1 ≤ li < ri ≤ n). The answer to the query li, ri is the number of such integers i (li ≤ i < ri), that si = si + 1.Ilya the Lion wants to help his friends but is there anyone to help him? Help Ilya, solve the problem. | Print m integers — the answers to the queries in the order in which they are given in the input. | C | b30e09449309b999473e4be6643d68cd | 770ec2471d5f9f6e339e4fdb8158be08 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"dp",
"implementation"
] | 1369927800 | ["......\n4\n3 4\n2 3\n1 6\n2 6", "#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line contains string s of length n (2 ≤ n ≤ 105). It is guaranteed that the given string only consists of characters "." and "#". The next line contains integer m (1 ≤ m ≤ 105) — the number of queries. Each of the next m lines contains the description of the corresponding query. The i-th line contains integers li, ri (1 ≤ li < ri ≤ n). | ["1\n1\n5\n4", "1\n1\n2\n2\n0"] | #include<stdio.h>
#include<string.h>
int main(){
int n,m,i,c=0,ans=0,j,k;
char str[100000];
gets(str);
scanf("%d", &m);
int x[m];
for(i=0;str[i];i++){
if(str[i]==str[i+1]){
c++;
x[i]=c;
}
else x[i]=c;
}
/*for(i=0;i<strlen(str);i++) printf("%d",x[i]);
return 0;*/
int a,b;
for(i=0;i<m;i++){
c=0;
scanf("%d %d", &a, &b);
if(a-2>=0) printf("%d\n", x[b-2]-x[a-2]);
else printf("%d\n",x[b-2]);
}
}
| |
Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.You've got string s = s1s2... sn (n is the length of the string), consisting only of characters "." and "#" and m queries. Each query is described by a pair of integers li, ri (1 ≤ li < ri ≤ n). The answer to the query li, ri is the number of such integers i (li ≤ i < ri), that si = si + 1.Ilya the Lion wants to help his friends but is there anyone to help him? Help Ilya, solve the problem. | Print m integers — the answers to the queries in the order in which they are given in the input. | C | b30e09449309b999473e4be6643d68cd | e611684594e4514bb06880a18f2775b3 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"dp",
"implementation"
] | 1369927800 | ["......\n4\n3 4\n2 3\n1 6\n2 6", "#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line contains string s of length n (2 ≤ n ≤ 105). It is guaranteed that the given string only consists of characters "." and "#". The next line contains integer m (1 ≤ m ≤ 105) — the number of queries. Each of the next m lines contains the description of the corresponding query. The i-th line contains integers li, ri (1 ≤ li < ri ≤ n). | ["1\n1\n5\n4", "1\n1\n2\n2\n0"] | #include<stdio.h>
#include<string.h>
int main()
{ char ch[100010];
long long int l, r, i, j, N[100011], q, ans, ct=0;
scanf("%s", ch);
long long int x=strlen(ch);
scanf("%lld", &q);
N[0]=0;
for(i=1; i<x; i++)
{ if(ch[i]==ch[i-1])
N[i]=N[i-1]+1;
else N[i]=N[i-1];
}
for(i=0; i<q; i++)
{ scanf("%lld %lld", &l, &r);
ans=N[r-1]-N[l-1];
printf("%lld\n", ans);
}
return 0;
}
| |
Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.You've got string s = s1s2... sn (n is the length of the string), consisting only of characters "." and "#" and m queries. Each query is described by a pair of integers li, ri (1 ≤ li < ri ≤ n). The answer to the query li, ri is the number of such integers i (li ≤ i < ri), that si = si + 1.Ilya the Lion wants to help his friends but is there anyone to help him? Help Ilya, solve the problem. | Print m integers — the answers to the queries in the order in which they are given in the input. | C | b30e09449309b999473e4be6643d68cd | b636e885bbbe6fa406b195f3cf59b98e | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"dp",
"implementation"
] | 1369927800 | ["......\n4\n3 4\n2 3\n1 6\n2 6", "#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line contains string s of length n (2 ≤ n ≤ 105). It is guaranteed that the given string only consists of characters "." and "#". The next line contains integer m (1 ≤ m ≤ 105) — the number of queries. Each of the next m lines contains the description of the corresponding query. The i-th line contains integers li, ri (1 ≤ li < ri ≤ n). | ["1\n1\n5\n4", "1\n1\n2\n2\n0"] | #include<stdio.h>
#include<string.h>
int dp[200000];
int main()
{
char arr[200001];
int m;
int arr1[100001];
int arr2[100001];
scanf("%s",arr);
scanf("%d",&m);
for(int i=0;i<m;i++)
{
scanf("%d %d",&arr1[i],&arr2[i]);
}
int k=strlen(arr);
// printf("%d",k);
for(int i=0;i<k-1;i++)
{
if(i==0)
{
if(arr[i]==arr[i+1])
dp[i]=1;
else
dp[i]=0;
}
else if(arr[i]==arr[i+1])
dp[i]=dp[i-1]+1;
else
dp[i]=dp[i-1];
}
dp[k-1]=dp[k-2];
for(int i=0;i<m;i++)
{
printf("%d\n", dp[arr2[i]-2]-dp[arr1[i]-2]);
}
} | |
Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.You've got string s = s1s2... sn (n is the length of the string), consisting only of characters "." and "#" and m queries. Each query is described by a pair of integers li, ri (1 ≤ li < ri ≤ n). The answer to the query li, ri is the number of such integers i (li ≤ i < ri), that si = si + 1.Ilya the Lion wants to help his friends but is there anyone to help him? Help Ilya, solve the problem. | Print m integers — the answers to the queries in the order in which they are given in the input. | C | b30e09449309b999473e4be6643d68cd | 8036c0aa57f7f82117d14b9722db2ece | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"dp",
"implementation"
] | 1369927800 | ["......\n4\n3 4\n2 3\n1 6\n2 6", "#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line contains string s of length n (2 ≤ n ≤ 105). It is guaranteed that the given string only consists of characters "." and "#". The next line contains integer m (1 ≤ m ≤ 105) — the number of queries. Each of the next m lines contains the description of the corresponding query. The i-th line contains integers li, ri (1 ≤ li < ri ≤ n). | ["1\n1\n5\n4", "1\n1\n2\n2\n0"] | #include<stdio.h>
#include <string.h>
#include <math.h>
int main(){
char str[100001];
int str2[100001]={0};
scanf("%s",str);
int len=strlen(str),l,r;
for(int i=0;i<strlen(str)-1;i++)
{
if(str[i]==str[i+1])
{
str2[i+1]++;
}
}
for(int i=1;i<len;i++)
{
str2[i]+=str2[i-1];
}
int tests;
scanf("%d",&tests);
for(int i=0;i<tests;i++)
{
scanf("%d %d",&l,&r);
if(l==1)
{
printf("%d\n",str2[r-1]);
}
else
{
printf("%d\n",(str2[r-1]-str2[l-1]));
}
}
} | |
Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.You've got string s = s1s2... sn (n is the length of the string), consisting only of characters "." and "#" and m queries. Each query is described by a pair of integers li, ri (1 ≤ li < ri ≤ n). The answer to the query li, ri is the number of such integers i (li ≤ i < ri), that si = si + 1.Ilya the Lion wants to help his friends but is there anyone to help him? Help Ilya, solve the problem. | Print m integers — the answers to the queries in the order in which they are given in the input. | C | b30e09449309b999473e4be6643d68cd | 50b616225a69becf9603c0cba3d096f5 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"dp",
"implementation"
] | 1369927800 | ["......\n4\n3 4\n2 3\n1 6\n2 6", "#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line contains string s of length n (2 ≤ n ≤ 105). It is guaranteed that the given string only consists of characters "." and "#". The next line contains integer m (1 ≤ m ≤ 105) — the number of queries. Each of the next m lines contains the description of the corresponding query. The i-th line contains integers li, ri (1 ≤ li < ri ≤ n). | ["1\n1\n5\n4", "1\n1\n2\n2\n0"] | #include<stdio.h>
#include <string.h>
#include <math.h>
int main(){
char str[100001];
int str2[100001]={0};
scanf("%s",str);
int l,r;
for(int i=0;i<100001;i++)
{
if(str[i+1]=='\0')
{
break;
}
if(str[i]==str[i+1])
{
str2[i+1]++;
}
}
for(int i=1;i<100001;i++)
{
str2[i]+=str2[i-1];
}
int tests;
scanf("%d",&tests);
while(tests--) {
scanf("%d %d", &l, &r);
printf("%d\n", (str2[r - 1] - str2[l - 1]));
}
} | |
Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.You've got string s = s1s2... sn (n is the length of the string), consisting only of characters "." and "#" and m queries. Each query is described by a pair of integers li, ri (1 ≤ li < ri ≤ n). The answer to the query li, ri is the number of such integers i (li ≤ i < ri), that si = si + 1.Ilya the Lion wants to help his friends but is there anyone to help him? Help Ilya, solve the problem. | Print m integers — the answers to the queries in the order in which they are given in the input. | C | b30e09449309b999473e4be6643d68cd | 70598dc37ac729e291aeb415cd4efaf1 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"dp",
"implementation"
] | 1369927800 | ["......\n4\n3 4\n2 3\n1 6\n2 6", "#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line contains string s of length n (2 ≤ n ≤ 105). It is guaranteed that the given string only consists of characters "." and "#". The next line contains integer m (1 ≤ m ≤ 105) — the number of queries. Each of the next m lines contains the description of the corresponding query. The i-th line contains integers li, ri (1 ≤ li < ri ≤ n). | ["1\n1\n5\n4", "1\n1\n2\n2\n0"] | #include<stdio.h>
#include <string.h>
#include <math.h>
int main(){
char str[100001];
int str2[100001]={0};
scanf("%s",str);
int len=strlen(str),l,r;
for(int i=0;i<strlen(str)-1;i++)
{
if(str[i]==str[i+1])
{
str2[i+1]++;
}
}
for(int i=1;i<len;i++)
{
str2[i]+=str2[i-1];
}
int tests;
scanf("%d",&tests);
while(tests--) {
scanf("%d %d", &l, &r);
printf("%d\n", (str2[r - 1] - str2[l - 1]));
}
} | |
Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.You've got string s = s1s2... sn (n is the length of the string), consisting only of characters "." and "#" and m queries. Each query is described by a pair of integers li, ri (1 ≤ li < ri ≤ n). The answer to the query li, ri is the number of such integers i (li ≤ i < ri), that si = si + 1.Ilya the Lion wants to help his friends but is there anyone to help him? Help Ilya, solve the problem. | Print m integers — the answers to the queries in the order in which they are given in the input. | C | b30e09449309b999473e4be6643d68cd | 483cd3292c75ef05dc4cb4280342925c | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"dp",
"implementation"
] | 1369927800 | ["......\n4\n3 4\n2 3\n1 6\n2 6", "#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line contains string s of length n (2 ≤ n ≤ 105). It is guaranteed that the given string only consists of characters "." and "#". The next line contains integer m (1 ≤ m ≤ 105) — the number of queries. Each of the next m lines contains the description of the corresponding query. The i-th line contains integers li, ri (1 ≤ li < ri ≤ n). | ["1\n1\n5\n4", "1\n1\n2\n2\n0"] | #include<string.h>
#include<stdio.h>
int main(){
int a[100002]={0},n,m,l,r,i,c=0;
char s[100002];
gets(s);
scanf("%d",&m);
n=strlen(s);
for(i=0;i<n-1;i++){
if(s[i]==s[i+1]) c++;
a[i+1]=c;
}
for(i=0;i<m;i++){
scanf("%d %d",&l,&r);
printf("%d\n",a[r-1]-a[l-1]);
}
} | |
Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.You've got string s = s1s2... sn (n is the length of the string), consisting only of characters "." and "#" and m queries. Each query is described by a pair of integers li, ri (1 ≤ li < ri ≤ n). The answer to the query li, ri is the number of such integers i (li ≤ i < ri), that si = si + 1.Ilya the Lion wants to help his friends but is there anyone to help him? Help Ilya, solve the problem. | Print m integers — the answers to the queries in the order in which they are given in the input. | C | b30e09449309b999473e4be6643d68cd | 2351e65d0d30e97d50096c36ffeb09cc | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"dp",
"implementation"
] | 1369927800 | ["......\n4\n3 4\n2 3\n1 6\n2 6", "#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line contains string s of length n (2 ≤ n ≤ 105). It is guaranteed that the given string only consists of characters "." and "#". The next line contains integer m (1 ≤ m ≤ 105) — the number of queries. Each of the next m lines contains the description of the corresponding query. The i-th line contains integers li, ri (1 ≤ li < ri ≤ n). | ["1\n1\n5\n4", "1\n1\n2\n2\n0"] | #include<string.h>
#include<stdio.h>
int main(){
int a[100002]={0},n,m,l,r,i,c=0;
char s[100002];
gets(s);
scanf("%d",&m);
n=strlen(s);
for(i=0;i<n-1;i++){
if(s[i]==s[i+1]) c++;
a[i+1]=c;
}
for(i=0;i<m;i++){
scanf("%d%d",&l,&r);
printf("%d\n",a[r-1]-a[l-1]);
}
} | |
Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.You've got string s = s1s2... sn (n is the length of the string), consisting only of characters "." and "#" and m queries. Each query is described by a pair of integers li, ri (1 ≤ li < ri ≤ n). The answer to the query li, ri is the number of such integers i (li ≤ i < ri), that si = si + 1.Ilya the Lion wants to help his friends but is there anyone to help him? Help Ilya, solve the problem. | Print m integers — the answers to the queries in the order in which they are given in the input. | C | b30e09449309b999473e4be6643d68cd | 066dab08888873f654c2a927783cb964 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"dp",
"implementation"
] | 1369927800 | ["......\n4\n3 4\n2 3\n1 6\n2 6", "#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line contains string s of length n (2 ≤ n ≤ 105). It is guaranteed that the given string only consists of characters "." and "#". The next line contains integer m (1 ≤ m ≤ 105) — the number of queries. Each of the next m lines contains the description of the corresponding query. The i-th line contains integers li, ri (1 ≤ li < ri ≤ n). | ["1\n1\n5\n4", "1\n1\n2\n2\n0"] | #include <stdio.h>
int main() {
char str[100005];
//Input the string with length n
scanf("%s", &str);
int dp[100005];
//memset(dp, 0, sizeof(int)*100005);
dp[0] = 0;
int i = 1;
while (str[i] != 0) {
if (str[i] == str[i-1]) dp[i] = dp[i-1]+1;
else dp[i] = dp[i-1];
i++;
}
int m,l,r;
scanf("%d", &m);
for (i = 0; i < m; i++) {
scanf("%d %d", &l, &r);
printf("%d\n", dp[r-1] - dp[l-1]);
}
return 0;
} | |
Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.You've got string s = s1s2... sn (n is the length of the string), consisting only of characters "." and "#" and m queries. Each query is described by a pair of integers li, ri (1 ≤ li < ri ≤ n). The answer to the query li, ri is the number of such integers i (li ≤ i < ri), that si = si + 1.Ilya the Lion wants to help his friends but is there anyone to help him? Help Ilya, solve the problem. | Print m integers — the answers to the queries in the order in which they are given in the input. | C | b30e09449309b999473e4be6643d68cd | 804e65f52085d18bb96b154c8d46ff17 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"dp",
"implementation"
] | 1369927800 | ["......\n4\n3 4\n2 3\n1 6\n2 6", "#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line contains string s of length n (2 ≤ n ≤ 105). It is guaranteed that the given string only consists of characters "." and "#". The next line contains integer m (1 ≤ m ≤ 105) — the number of queries. Each of the next m lines contains the description of the corresponding query. The i-th line contains integers li, ri (1 ≤ li < ri ≤ n). | ["1\n1\n5\n4", "1\n1\n2\n2\n0"] | #include <stdio.h>
#include <string.h>
#define rep(i,a,b) for (long i=a; i<b; i++)
void generate(char *s, int *arr, long length) {
rep (i,0,length-1) {
if (s[i]==s[i+1]) {
arr[i]=1;
} else {
arr[i]=0;
}
}
arr[length-1]=0;
}
void accumulate(int *arro, long *arrt, long length) {
arrt[0]=0;
rep (i,1,length) arrt[i]=arrt[i-1]+arro[i-1];
}
int process(char *s, long m) {
long len=strlen(s),l,r;
int fill[len];
long acc[len];
generate(s,fill,len);
accumulate(fill,acc,len);
rep (i,0,m) {
scanf("%ld %ld\n",&l,&r);
printf("%ld\n",acc[r-1]-acc[l-1]);
}
}
int main() {
char str[100001];
long queries;
scanf("%s\n%ld\n",str,&queries);
process(str,queries);
return 0;
} | |
Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.You've got string s = s1s2... sn (n is the length of the string), consisting only of characters "." and "#" and m queries. Each query is described by a pair of integers li, ri (1 ≤ li < ri ≤ n). The answer to the query li, ri is the number of such integers i (li ≤ i < ri), that si = si + 1.Ilya the Lion wants to help his friends but is there anyone to help him? Help Ilya, solve the problem. | Print m integers — the answers to the queries in the order in which they are given in the input. | C | b30e09449309b999473e4be6643d68cd | 1ddb5574f06e94a906fd436e2f27a621 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"dp",
"implementation"
] | 1369927800 | ["......\n4\n3 4\n2 3\n1 6\n2 6", "#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line contains string s of length n (2 ≤ n ≤ 105). It is guaranteed that the given string only consists of characters "." and "#". The next line contains integer m (1 ≤ m ≤ 105) — the number of queries. Each of the next m lines contains the description of the corresponding query. The i-th line contains integers li, ri (1 ≤ li < ri ≤ n). | ["1\n1\n5\n4", "1\n1\n2\n2\n0"] | #include <stdio.h>
#include <string.h>
int main()
{
int L, D, i, j, N, dp[100000] = {0};
char arr[100001];
scanf("%s", arr);
for (i = 0; i < strlen(arr) - 1; i++){
if (i == 0 && arr[i] == arr[i + 1]) dp[0] = 1;
else if (arr[i] == arr[i + 1]) dp[i] = dp[i - 1] + 1;
else if (i != 0) dp[i] = dp[i - 1];
// printf("dp[%d] is %d\n", i , dp[i]);
}
dp[i] = dp[i - 1];
//printf("dp[%d] is %d\n", i, dp[i]);
arr[i + 1] = 'a';
scanf("%d", &N);
int sol;
for (i = 0; i < N; i++) {
scanf("%d %d", &L, &D);
if (arr[L - 1] == arr[L] && arr[D - 1] == arr[D] || arr[L - 1] != arr[L] && arr[D - 1] != arr[D]) sol = dp[D - 1] - dp[L - 1];
else if (arr[L - 1] == arr[L] && arr[D - 1] != arr[D]) sol = dp[D - 1] - dp[L - 1] + 1;
else sol = dp[D - 1] - dp[L - 1] - 1;
printf("%d\n", sol);
}
return 0;
} | |
Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.You've got string s = s1s2... sn (n is the length of the string), consisting only of characters "." and "#" and m queries. Each query is described by a pair of integers li, ri (1 ≤ li < ri ≤ n). The answer to the query li, ri is the number of such integers i (li ≤ i < ri), that si = si + 1.Ilya the Lion wants to help his friends but is there anyone to help him? Help Ilya, solve the problem. | Print m integers — the answers to the queries in the order in which they are given in the input. | C | b30e09449309b999473e4be6643d68cd | 61eac8bf815eb29f0961db9684a7e0f8 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"dp",
"implementation"
] | 1369927800 | ["......\n4\n3 4\n2 3\n1 6\n2 6", "#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line contains string s of length n (2 ≤ n ≤ 105). It is guaranteed that the given string only consists of characters "." and "#". The next line contains integer m (1 ≤ m ≤ 105) — the number of queries. Each of the next m lines contains the description of the corresponding query. The i-th line contains integers li, ri (1 ≤ li < ri ≤ n). | ["1\n1\n5\n4", "1\n1\n2\n2\n0"] | #include <stdio.h>
#include <string.h>
int main()
{
int L, D, i, j, N, dp[100000] = {0};
char arr[100001];
scanf("%s", arr);
for (i = 0; i < strlen(arr) - 1; i++){
if (i == 0 && arr[i] == arr[i + 1]) dp[0] = 1;
else if (arr[i] == arr[i + 1]) dp[i] = dp[i - 1] + 1;
else if (i != 0) dp[i] = dp[i - 1];
// printf("dp[%d] is %d\n", i , dp[i]);
}
dp[i] = dp[i - 1];
// printf("dp[%d] is %d\n", i, dp[i]);
arr[i + 1] = 'a';
scanf("%d", &N);
int sol;
for (i = 0; i < N; i++) {
scanf("%d %d", &L, &D);
if (arr[L - 1] == arr[L] && arr[D - 1] == arr[D]) sol = dp[D - 1] - dp[L - 1];
else if (arr[L - 1] == arr[L] && arr[D - 1] != arr[D]) sol = dp[D - 1] - dp[L - 1] + 1;
else if (arr[L - 1] != arr[L] && arr[D - 1] == arr[D]) sol = dp[D - 1] - dp[L - 1] - 1;
else if (arr[L - 1] != arr[L] && arr[D - 1] != arr[D]) sol = dp[D - 1] - dp[L - 1];
printf("%d\n", sol);
}
return 0;
}
| |
Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.You've got string s = s1s2... sn (n is the length of the string), consisting only of characters "." and "#" and m queries. Each query is described by a pair of integers li, ri (1 ≤ li < ri ≤ n). The answer to the query li, ri is the number of such integers i (li ≤ i < ri), that si = si + 1.Ilya the Lion wants to help his friends but is there anyone to help him? Help Ilya, solve the problem. | Print m integers — the answers to the queries in the order in which they are given in the input. | C | b30e09449309b999473e4be6643d68cd | c5f697826abce73720f60ee0f3da3e82 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"dp",
"implementation"
] | 1369927800 | ["......\n4\n3 4\n2 3\n1 6\n2 6", "#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line contains string s of length n (2 ≤ n ≤ 105). It is guaranteed that the given string only consists of characters "." and "#". The next line contains integer m (1 ≤ m ≤ 105) — the number of queries. Each of the next m lines contains the description of the corresponding query. The i-th line contains integers li, ri (1 ≤ li < ri ≤ n). | ["1\n1\n5\n4", "1\n1\n2\n2\n0"] | #include <stdio.h>
#include <string.h>
int main()
{
int L, D, i, j, N, dp[100000] = {0};
char arr[100001];
scanf("%s", arr);
for (i = 0; i < strlen(arr) - 1; i++){
if (i == 0 && arr[i] == arr[i + 1]) dp[0] = 1;
else if (arr[i] == arr[i + 1]) dp[i] = dp[i - 1] + 1;
else if (i != 0) dp[i] = dp[i - 1];
// printf("dp[%d] is %d\n", i , dp[i]);
}
dp[i] = dp[i - 1];
// printf("dp[%d] is %d\n", i, dp[i]);
arr[i + 1] = 'a';
scanf("%d", &N);
int sol;
for (i = 0; i < N; i++) {
scanf("%d %d", &L, &D);
if (arr[L - 1] == arr[L] && arr[D - 1] == arr[D] || arr[L - 1] != arr[L] && arr[D - 1] != arr[D]) sol = dp[D - 1] - dp[L - 1];
else if (arr[L - 1] == arr[L] && arr[D - 1] != arr[D]) sol = dp[D - 1] - dp[L - 1] + 1;
else sol = dp[D - 1] - dp[L - 1] - 1;
printf("%d\n", sol);
}
return 0;
} | |
Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.You've got string s = s1s2... sn (n is the length of the string), consisting only of characters "." and "#" and m queries. Each query is described by a pair of integers li, ri (1 ≤ li < ri ≤ n). The answer to the query li, ri is the number of such integers i (li ≤ i < ri), that si = si + 1.Ilya the Lion wants to help his friends but is there anyone to help him? Help Ilya, solve the problem. | Print m integers — the answers to the queries in the order in which they are given in the input. | C | b30e09449309b999473e4be6643d68cd | 91f2ec1339878371635b9a2587f97617 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"dp",
"implementation"
] | 1369927800 | ["......\n4\n3 4\n2 3\n1 6\n2 6", "#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line contains string s of length n (2 ≤ n ≤ 105). It is guaranteed that the given string only consists of characters "." and "#". The next line contains integer m (1 ≤ m ≤ 105) — the number of queries. Each of the next m lines contains the description of the corresponding query. The i-th line contains integers li, ri (1 ≤ li < ri ≤ n). | ["1\n1\n5\n4", "1\n1\n2\n2\n0"] | #include <stdio.h>
#include <string.h>
typedef long long LL;
int main()
{
char a[100005];
char b[100005];
scanf("%s",a);
int len=strlen(a);
b[0]=8;
for(LL i=0;i<len;i++)
{
b[i+1]=a[i];
}
LL arr[len+1];
arr[1]=0;
for(LL i=2;i<=len;i++)
{
arr[i]=arr[i-1]+(b[i]==b[i-1]);
}
LL t,left,right;
scanf("%lld",&t);
while(t--)
{
scanf("%lld %lld",&left,&right);
LL ans=arr[right]-arr[left];
printf("%lld\n",ans);
}
}
| |
Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.You've got string s = s1s2... sn (n is the length of the string), consisting only of characters "." and "#" and m queries. Each query is described by a pair of integers li, ri (1 ≤ li < ri ≤ n). The answer to the query li, ri is the number of such integers i (li ≤ i < ri), that si = si + 1.Ilya the Lion wants to help his friends but is there anyone to help him? Help Ilya, solve the problem. | Print m integers — the answers to the queries in the order in which they are given in the input. | C | b30e09449309b999473e4be6643d68cd | 64e8fe35c795c2fc99909ac7f084ff9d | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"dp",
"implementation"
] | 1369927800 | ["......\n4\n3 4\n2 3\n1 6\n2 6", "#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line contains string s of length n (2 ≤ n ≤ 105). It is guaranteed that the given string only consists of characters "." and "#". The next line contains integer m (1 ≤ m ≤ 105) — the number of queries. Each of the next m lines contains the description of the corresponding query. The i-th line contains integers li, ri (1 ≤ li < ri ≤ n). | ["1\n1\n5\n4", "1\n1\n2\n2\n0"] | #include<stdio.h>
int main(){
char str[100001];
int DP[100000];
scanf("%s",str);
int count=0,m;
int a,b;
for(int i=1;str[i]!='\0';i++){
if(str[i]==str[i-1]){
count++;
}
DP[i]=count;
}
scanf("%d",&m);
while(m--){
scanf("%d%d",&a,&b);
printf("%d\n",DP[b-1]-DP[a-1]);
}
return 0;
} | |
Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.You've got string s = s1s2... sn (n is the length of the string), consisting only of characters "." and "#" and m queries. Each query is described by a pair of integers li, ri (1 ≤ li < ri ≤ n). The answer to the query li, ri is the number of such integers i (li ≤ i < ri), that si = si + 1.Ilya the Lion wants to help his friends but is there anyone to help him? Help Ilya, solve the problem. | Print m integers — the answers to the queries in the order in which they are given in the input. | C | b30e09449309b999473e4be6643d68cd | f3859e143877491c2409074f99ecdd99 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"dp",
"implementation"
] | 1369927800 | ["......\n4\n3 4\n2 3\n1 6\n2 6", "#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line contains string s of length n (2 ≤ n ≤ 105). It is guaranteed that the given string only consists of characters "." and "#". The next line contains integer m (1 ≤ m ≤ 105) — the number of queries. Each of the next m lines contains the description of the corresponding query. The i-th line contains integers li, ri (1 ≤ li < ri ≤ n). | ["1\n1\n5\n4", "1\n1\n2\n2\n0"] | #include<stdio.h>
int main()
{
char s[100000];
scanf("%s",s);
int k,j,m,a,b,d=0,c[100001]={0},n=0;
scanf("%d",&m);
while(s[n]!='\0')
n++;
for(k=0;k<=n;k++)
{
if(s[k-1]==s[k])
c[k]=++d;
else
c[k]=d;
}
for(j=0;j<m;j++)
{
scanf("%d %d",&a,&b);
printf("%d\n",c[b-1]-c[a-1]);
}
return 0;
}
| |
Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.You've got string s = s1s2... sn (n is the length of the string), consisting only of characters "." and "#" and m queries. Each query is described by a pair of integers li, ri (1 ≤ li < ri ≤ n). The answer to the query li, ri is the number of such integers i (li ≤ i < ri), that si = si + 1.Ilya the Lion wants to help his friends but is there anyone to help him? Help Ilya, solve the problem. | Print m integers — the answers to the queries in the order in which they are given in the input. | C | b30e09449309b999473e4be6643d68cd | 4ba6cc3bdc9a2ce4b9dfea2718e2b0bc | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"dp",
"implementation"
] | 1369927800 | ["......\n4\n3 4\n2 3\n1 6\n2 6", "#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line contains string s of length n (2 ≤ n ≤ 105). It is guaranteed that the given string only consists of characters "." and "#". The next line contains integer m (1 ≤ m ≤ 105) — the number of queries. Each of the next m lines contains the description of the corresponding query. The i-th line contains integers li, ri (1 ≤ li < ri ≤ n). | ["1\n1\n5\n4", "1\n1\n2\n2\n0"] | #include<stdio.h>
#include<string.h>
int main()
{
char str[2000001];
scanf("%s",str);
int n=strlen(str);
int count[100000]={0};
int i;
int x=0;
for(i=0;i<n-1;i++)
{
if(str[i]==str[i+1])
{
count[i]=x+1;
x++;
}
else
{
count[i]=x;
}
}
long long int q;
scanf("%lld",&q);
while(q--)
{
int l,r;
scanf("%d%d",&l,&r);
int cn=count[r-2]-count[l-2];
printf("%d\n",cn);
}
return 0;
}
| |
Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.You've got string s = s1s2... sn (n is the length of the string), consisting only of characters "." and "#" and m queries. Each query is described by a pair of integers li, ri (1 ≤ li < ri ≤ n). The answer to the query li, ri is the number of such integers i (li ≤ i < ri), that si = si + 1.Ilya the Lion wants to help his friends but is there anyone to help him? Help Ilya, solve the problem. | Print m integers — the answers to the queries in the order in which they are given in the input. | C | b30e09449309b999473e4be6643d68cd | bfd0371a3a22a52e486dd9ccaf31f011 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"dp",
"implementation"
] | 1369927800 | ["......\n4\n3 4\n2 3\n1 6\n2 6", "#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line contains string s of length n (2 ≤ n ≤ 105). It is guaranteed that the given string only consists of characters "." and "#". The next line contains integer m (1 ≤ m ≤ 105) — the number of queries. Each of the next m lines contains the description of the corresponding query. The i-th line contains integers li, ri (1 ≤ li < ri ≤ n). | ["1\n1\n5\n4", "1\n1\n2\n2\n0"] | /* Bismillahir-Rahmanir-Rahim */
/*
Solved By:- MD. Hasibul Hossain Rezvi
CSE 14th Batch
Comilla University
*/
#include<stdio.h>
#include<math.h>
#include<string.h>
#define ll long long int
#define db double
#define py printf("YES\n")
#define pn printf("NO\n")
#define nl printf("\n");
int main()
{
int i,k,m,n,l,r,ci=0,cn=0,a[100005];
char in[100005],c;
scanf("%s",&in);
n=strlen(in);
in[n]=in[n-1];
scanf("%d",&m);
a[0]=0;
for(i=0; i<n; i++)
{
if(in[i]==in[i+1])
a[i+1]=a[i]+1;
else
a[i+1]=a[i];
}
while (m--)
{
scanf("%d%d",&l,&r);
printf("%d\n",a[r-1]-a[l-1]);
}
return 0;
}
| |
Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.You've got string s = s1s2... sn (n is the length of the string), consisting only of characters "." and "#" and m queries. Each query is described by a pair of integers li, ri (1 ≤ li < ri ≤ n). The answer to the query li, ri is the number of such integers i (li ≤ i < ri), that si = si + 1.Ilya the Lion wants to help his friends but is there anyone to help him? Help Ilya, solve the problem. | Print m integers — the answers to the queries in the order in which they are given in the input. | C | b30e09449309b999473e4be6643d68cd | c38f7037b5e6a674ebb89c39e9013f76 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"dp",
"implementation"
] | 1369927800 | ["......\n4\n3 4\n2 3\n1 6\n2 6", "#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line contains string s of length n (2 ≤ n ≤ 105). It is guaranteed that the given string only consists of characters "." and "#". The next line contains integer m (1 ≤ m ≤ 105) — the number of queries. Each of the next m lines contains the description of the corresponding query. The i-th line contains integers li, ri (1 ≤ li < ri ≤ n). | ["1\n1\n5\n4", "1\n1\n2\n2\n0"] | #include <stdio.h>
#include <string.h>
int main(){
int length,n,l,r,count=0;
char s[100000];
gets(s);
length=strlen(s);
int arr[length-1];
for(int i=0;i<length-1;++i){
if(s[i]==s[i+1])
count++;
arr[i]=count;
}
scanf("%d",&n);
while(n--){
scanf("%d%d",&l,&r);
if(l==1)
printf("%d\n",arr[r-2]);
else
printf("%d\n",arr[r-2]-arr[l-2]);
}
return 0;
} | |
Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.You've got string s = s1s2... sn (n is the length of the string), consisting only of characters "." and "#" and m queries. Each query is described by a pair of integers li, ri (1 ≤ li < ri ≤ n). The answer to the query li, ri is the number of such integers i (li ≤ i < ri), that si = si + 1.Ilya the Lion wants to help his friends but is there anyone to help him? Help Ilya, solve the problem. | Print m integers — the answers to the queries in the order in which they are given in the input. | C | b30e09449309b999473e4be6643d68cd | 1649637bad2e5a77db760d869799890a | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"dp",
"implementation"
] | 1369927800 | ["......\n4\n3 4\n2 3\n1 6\n2 6", "#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line contains string s of length n (2 ≤ n ≤ 105). It is guaranteed that the given string only consists of characters "." and "#". The next line contains integer m (1 ≤ m ≤ 105) — the number of queries. Each of the next m lines contains the description of the corresponding query. The i-th line contains integers li, ri (1 ≤ li < ri ≤ n). | ["1\n1\n5\n4", "1\n1\n2\n2\n0"] | #pragma GCC optimize("O2")
#include <stdio.h>
#include <string.h>
char data[100005];
int dp[100005];
int main()
{
scanf("%s", data+1);
data[0] = ' ';
int len = strlen(data);
dp[0] = 0;
int i;
for(i = 1; i < len; i++)
{
if(data[i] == data[i+1])
dp[i] = dp[i-1] + 1;
else
dp[i] = dp[i-1];
}
dp[len] = dp[len-1];
int q;
scanf("%d", &q);
while(q--)
{
int left, right;
scanf("%d%d", &left, &right);
printf("%d\n", dp[right-1] - dp[left-1]);
}
} | |
Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.You've got string s = s1s2... sn (n is the length of the string), consisting only of characters "." and "#" and m queries. Each query is described by a pair of integers li, ri (1 ≤ li < ri ≤ n). The answer to the query li, ri is the number of such integers i (li ≤ i < ri), that si = si + 1.Ilya the Lion wants to help his friends but is there anyone to help him? Help Ilya, solve the problem. | Print m integers — the answers to the queries in the order in which they are given in the input. | C | b30e09449309b999473e4be6643d68cd | 689ac76af612b2c16fcbcfe2bed7d3c7 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"dp",
"implementation"
] | 1369927800 | ["......\n4\n3 4\n2 3\n1 6\n2 6", "#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line contains string s of length n (2 ≤ n ≤ 105). It is guaranteed that the given string only consists of characters "." and "#". The next line contains integer m (1 ≤ m ≤ 105) — the number of queries. Each of the next m lines contains the description of the corresponding query. The i-th line contains integers li, ri (1 ≤ li < ri ≤ n). | ["1\n1\n5\n4", "1\n1\n2\n2\n0"] | #include <stdio.h>
#include <string.h>
char data[100005];
int dp[100005];
int main()
{
scanf("%s", data+1);
data[0] = ' ';
int len = strlen(data);
dp[0] = 0;
for(int i = 1; i < len; i++)
{
if(data[i] == data[i+1])
dp[i] = dp[i-1] + 1;
else
dp[i] = dp[i-1];
}
dp[len] = dp[len-1];
int q;
scanf("%d", &q);
while(q--)
{
int left, right;
scanf("%d%d", &left, &right);
printf("%d\n", dp[right-1] - dp[left-1]);
}
} | |
Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.You've got string s = s1s2... sn (n is the length of the string), consisting only of characters "." and "#" and m queries. Each query is described by a pair of integers li, ri (1 ≤ li < ri ≤ n). The answer to the query li, ri is the number of such integers i (li ≤ i < ri), that si = si + 1.Ilya the Lion wants to help his friends but is there anyone to help him? Help Ilya, solve the problem. | Print m integers — the answers to the queries in the order in which they are given in the input. | C | b30e09449309b999473e4be6643d68cd | 30564b5144c15fbc2c38a065e2b90766 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"dp",
"implementation"
] | 1369927800 | ["......\n4\n3 4\n2 3\n1 6\n2 6", "#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line contains string s of length n (2 ≤ n ≤ 105). It is guaranteed that the given string only consists of characters "." and "#". The next line contains integer m (1 ≤ m ≤ 105) — the number of queries. Each of the next m lines contains the description of the corresponding query. The i-th line contains integers li, ri (1 ≤ li < ri ≤ n). | ["1\n1\n5\n4", "1\n1\n2\n2\n0"] | #include <stdio.h>
char data[100005];
int dp[100005];
int main()
{
scanf("%s", data+1);
data[0] = ' ';
// int len = strlen(data);
dp[0] = 0;
int i;
for(i = 1; data[i]; i++)
{
if(data[i] == data[i+1])
dp[i] = dp[i-1] + 1;
else
dp[i] = dp[i-1];
}
//dp[len] = dp[len-1];
dp[i-1] = dp[i-2];
int q;
scanf("%d", &q);
while(q--)
{
int left, right;
scanf("%d%d", &left, &right);
printf("%d\n", dp[right-1] - dp[left-1]);
}
} | |
Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.You've got string s = s1s2... sn (n is the length of the string), consisting only of characters "." and "#" and m queries. Each query is described by a pair of integers li, ri (1 ≤ li < ri ≤ n). The answer to the query li, ri is the number of such integers i (li ≤ i < ri), that si = si + 1.Ilya the Lion wants to help his friends but is there anyone to help him? Help Ilya, solve the problem. | Print m integers — the answers to the queries in the order in which they are given in the input. | C | b30e09449309b999473e4be6643d68cd | ba6513a1fc5f1d9eba4d618dc4958324 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"dp",
"implementation"
] | 1369927800 | ["......\n4\n3 4\n2 3\n1 6\n2 6", "#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line contains string s of length n (2 ≤ n ≤ 105). It is guaranteed that the given string only consists of characters "." and "#". The next line contains integer m (1 ≤ m ≤ 105) — the number of queries. Each of the next m lines contains the description of the corresponding query. The i-th line contains integers li, ri (1 ≤ li < ri ≤ n). | ["1\n1\n5\n4", "1\n1\n2\n2\n0"] | #include <stdio.h>
char data[100005];
int dp[100005];
int main()
{
scanf("%s", data+1);
data[0] = ' ';
// int len = strlen(data);
dp[0] = 0;
int i;
for(i = 1; data[i]; i++)
{
dp[i] = (data[i] == data[i+1]) ? dp[i-1]+1 : dp[i-1];
/* if(data[i] == data[i+1])
dp[i] = dp[i-1] + 1;
else
dp[i] = dp[i-1];*/
}
//dp[len] = dp[len-1];
dp[i-1] = dp[i-2];
int q;
scanf("%d", &q);
while(q--)
{
int left, right;
scanf("%d%d", &left, &right);
printf("%d\n", dp[right-1] - dp[left-1]);
}
} | |
Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.You've got string s = s1s2... sn (n is the length of the string), consisting only of characters "." and "#" and m queries. Each query is described by a pair of integers li, ri (1 ≤ li < ri ≤ n). The answer to the query li, ri is the number of such integers i (li ≤ i < ri), that si = si + 1.Ilya the Lion wants to help his friends but is there anyone to help him? Help Ilya, solve the problem. | Print m integers — the answers to the queries in the order in which they are given in the input. | C | b30e09449309b999473e4be6643d68cd | 70e02d7ba0660ba7c94c88189db30a12 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"dp",
"implementation"
] | 1369927800 | ["......\n4\n3 4\n2 3\n1 6\n2 6", "#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line contains string s of length n (2 ≤ n ≤ 105). It is guaranteed that the given string only consists of characters "." and "#". The next line contains integer m (1 ≤ m ≤ 105) — the number of queries. Each of the next m lines contains the description of the corresponding query. The i-th line contains integers li, ri (1 ≤ li < ri ≤ n). | ["1\n1\n5\n4", "1\n1\n2\n2\n0"] | #include <stdio.h>
char data[100005];
int dp[100005];
int main()
{
scanf("%s", data+1);
data[0] = ' ';
// int len = strlen(data);
dp[0] = 0;
int i;
for(i = 1; data[i]; i++)
{
// dp[i] = (data[i] == data[i+1]) ? dp[i-1]+1 : dp[i-1];
dp[i] = dp[i-1] + (data[i] == data[i+1]);
/* if(data[i] == data[i+1])
dp[i] = dp[i-1] + 1;
else
dp[i] = dp[i-1];*/
}
//dp[len] = dp[len-1];
dp[i-1] = dp[i-2];
int q;
scanf("%d", &q);
while(q--)
{
int left, right;
scanf("%d%d", &left, &right);
printf("%d\n", dp[right-1] - dp[left-1]);
}
} | |
Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.You've got string s = s1s2... sn (n is the length of the string), consisting only of characters "." and "#" and m queries. Each query is described by a pair of integers li, ri (1 ≤ li < ri ≤ n). The answer to the query li, ri is the number of such integers i (li ≤ i < ri), that si = si + 1.Ilya the Lion wants to help his friends but is there anyone to help him? Help Ilya, solve the problem. | Print m integers — the answers to the queries in the order in which they are given in the input. | C | b30e09449309b999473e4be6643d68cd | d44c63d6a4e386ef2bd2a3603bc86aec | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"dp",
"implementation"
] | 1369927800 | ["......\n4\n3 4\n2 3\n1 6\n2 6", "#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line contains string s of length n (2 ≤ n ≤ 105). It is guaranteed that the given string only consists of characters "." and "#". The next line contains integer m (1 ≤ m ≤ 105) — the number of queries. Each of the next m lines contains the description of the corresponding query. The i-th line contains integers li, ri (1 ≤ li < ri ≤ n). | ["1\n1\n5\n4", "1\n1\n2\n2\n0"] | #include <stdio.h>
#include <string.h>
#define MAX 100000
char string[MAX+1];
int ans[MAX+1];
int main(){
scanf("%s", string);
int len = strlen(string);
int count = 0;
for (int i = 0 ; i < len-1; i++){ //loop: n times
if (string[i] == string[i+1]){
count++;
}
ans[i] = count;
//printf("array:%d count:%d\n", ans[i], count);
}
int m;
scanf("%d", &m);
int l, r;
for (int i = 0; i < m; i++){ //loop: m times
scanf("%d%d", &l, &r);
printf("%d\n", ans[(r-1)-1] - ans[(l-1)-1]);
}
} | |
Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.You've got string s = s1s2... sn (n is the length of the string), consisting only of characters "." and "#" and m queries. Each query is described by a pair of integers li, ri (1 ≤ li < ri ≤ n). The answer to the query li, ri is the number of such integers i (li ≤ i < ri), that si = si + 1.Ilya the Lion wants to help his friends but is there anyone to help him? Help Ilya, solve the problem. | Print m integers — the answers to the queries in the order in which they are given in the input. | C | b30e09449309b999473e4be6643d68cd | cdc896f7993474219eb2f50ce8f89a6a | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"dp",
"implementation"
] | 1369927800 | ["......\n4\n3 4\n2 3\n1 6\n2 6", "#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line contains string s of length n (2 ≤ n ≤ 105). It is guaranteed that the given string only consists of characters "." and "#". The next line contains integer m (1 ≤ m ≤ 105) — the number of queries. Each of the next m lines contains the description of the corresponding query. The i-th line contains integers li, ri (1 ≤ li < ri ≤ n). | ["1\n1\n5\n4", "1\n1\n2\n2\n0"] | #include <stdio.h>
int main(){
int m,l,r,i=0,sum=0;
int a[100001];
char s[100001],c;
while((c=getchar())!='\n'){
i++;
s[i]=c;
if(i>=2)
if(s[i]==s[i-1])
sum++;
a[i]=sum;
}
scanf("%d",&m);
while(m--){
scanf("%d%d",&l,&r);
printf("%d\n",a[r]-a[l]);
}
} | |
Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.You've got string s = s1s2... sn (n is the length of the string), consisting only of characters "." and "#" and m queries. Each query is described by a pair of integers li, ri (1 ≤ li < ri ≤ n). The answer to the query li, ri is the number of such integers i (li ≤ i < ri), that si = si + 1.Ilya the Lion wants to help his friends but is there anyone to help him? Help Ilya, solve the problem. | Print m integers — the answers to the queries in the order in which they are given in the input. | C | b30e09449309b999473e4be6643d68cd | b86abec944ab8ae1f36eeb0a8bef8e1b | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"dp",
"implementation"
] | 1369927800 | ["......\n4\n3 4\n2 3\n1 6\n2 6", "#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line contains string s of length n (2 ≤ n ≤ 105). It is guaranteed that the given string only consists of characters "." and "#". The next line contains integer m (1 ≤ m ≤ 105) — the number of queries. Each of the next m lines contains the description of the corresponding query. The i-th line contains integers li, ri (1 ≤ li < ri ≤ n). | ["1\n1\n5\n4", "1\n1\n2\n2\n0"] | #include<stdio.h>
#include<string.h>
int main()
{
int m,i,p,len,sum[100005]={},cum[100005];
char c[100005];
scanf("%s",&c);
getchar();
len=strlen(c);
for(i=0;i<len-1;i++){
if(c[i]==c[i+1])
sum[i]=1;
}
cum[0]=sum[0];
for(i=1;i<len;i++){
cum[i]=cum[i-1]+sum[i];
}
scanf("%d",&m);
for(i=0;i<m;i++){
int count=0,j,a[100005],b[100005];
scanf("%d %d",&a[i],&b[i]);
count=cum[b[i]-2]-cum[a[i]-2];
printf("%d\n",count);
}
}
| |
Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.You've got string s = s1s2... sn (n is the length of the string), consisting only of characters "." and "#" and m queries. Each query is described by a pair of integers li, ri (1 ≤ li < ri ≤ n). The answer to the query li, ri is the number of such integers i (li ≤ i < ri), that si = si + 1.Ilya the Lion wants to help his friends but is there anyone to help him? Help Ilya, solve the problem. | Print m integers — the answers to the queries in the order in which they are given in the input. | C | b30e09449309b999473e4be6643d68cd | 70a62b466d04880527aeabe232826ac9 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"dp",
"implementation"
] | 1369927800 | ["......\n4\n3 4\n2 3\n1 6\n2 6", "#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line contains string s of length n (2 ≤ n ≤ 105). It is guaranteed that the given string only consists of characters "." and "#". The next line contains integer m (1 ≤ m ≤ 105) — the number of queries. Each of the next m lines contains the description of the corresponding query. The i-th line contains integers li, ri (1 ≤ li < ri ≤ n). | ["1\n1\n5\n4", "1\n1\n2\n2\n0"] | #include<stdio.h>
int main()
{
int m,l,r,i,j,a2[100000];
char a[1000000];
gets(a);
l=0;
m=strlen(a);
for(i=1; i<m; i++)
{
if(a[i-1]==a[i])
l=l+1;
a2[i]=l;
}
a2[i]=l;
scanf("%d",&m);
for(i=0; i<m; i++)
{
scanf("%d%d",&l,&r);
printf("%d\n",a2[r-1]-a2[l-1]);
}
} | |
Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.You've got string s = s1s2... sn (n is the length of the string), consisting only of characters "." and "#" and m queries. Each query is described by a pair of integers li, ri (1 ≤ li < ri ≤ n). The answer to the query li, ri is the number of such integers i (li ≤ i < ri), that si = si + 1.Ilya the Lion wants to help his friends but is there anyone to help him? Help Ilya, solve the problem. | Print m integers — the answers to the queries in the order in which they are given in the input. | C | b30e09449309b999473e4be6643d68cd | d79e26d3c7364808f8dab877095ad906 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"dp",
"implementation"
] | 1369927800 | ["......\n4\n3 4\n2 3\n1 6\n2 6", "#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line contains string s of length n (2 ≤ n ≤ 105). It is guaranteed that the given string only consists of characters "." and "#". The next line contains integer m (1 ≤ m ≤ 105) — the number of queries. Each of the next m lines contains the description of the corresponding query. The i-th line contains integers li, ri (1 ≤ li < ri ≤ n). | ["1\n1\n5\n4", "1\n1\n2\n2\n0"] | #include<stdio.h>
int main()
{
int c,m,l,r,i,j,a2[100000];
char a[1000000];
gets(a);
scanf("%d",&m);
c=0;
int L=strlen(a);
for(i=1;i<L;i++)
{
if(a[i-1]==a[i])
{
c=c+1;
a2[i]=c;
}
else
a2[i]=c;
}
a2[i]=c;
for(i=0;i<m;i++)
{
scanf("%d%d",&l,&r);
c=a2[r-1]-a2[l-1];
printf("%d\n",c);
}
}
| |
Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.You've got string s = s1s2... sn (n is the length of the string), consisting only of characters "." and "#" and m queries. Each query is described by a pair of integers li, ri (1 ≤ li < ri ≤ n). The answer to the query li, ri is the number of such integers i (li ≤ i < ri), that si = si + 1.Ilya the Lion wants to help his friends but is there anyone to help him? Help Ilya, solve the problem. | Print m integers — the answers to the queries in the order in which they are given in the input. | C | b30e09449309b999473e4be6643d68cd | 763ac8a4fee0a7d0b8be63ea11e40578 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"dp",
"implementation"
] | 1369927800 | ["......\n4\n3 4\n2 3\n1 6\n2 6", "#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line contains string s of length n (2 ≤ n ≤ 105). It is guaranteed that the given string only consists of characters "." and "#". The next line contains integer m (1 ≤ m ≤ 105) — the number of queries. Each of the next m lines contains the description of the corresponding query. The i-th line contains integers li, ri (1 ≤ li < ri ≤ n). | ["1\n1\n5\n4", "1\n1\n2\n2\n0"] | #include<stdio.h>
int main()
{
int c,m,l,r,i,j,a2[100000];
char a[1000000];
gets(a);
scanf("%d",&m);
c=0;
int L=strlen(a);
for(i=1;i<L;i++)
{
if(a[i-1]==a[i])
{
c=c+1;
a2[i]=c;
}
else
a2[i]=c;
}
a2[i]=c;
//for(i=1;i<L;i++)
// printf("%d\n",a2[i]);
for(i=0;i<m;i++)
{
scanf("%d%d",&l,&r);
c=a2[r-1]-a2[l-1];
if(l==1)
printf("%d\n",a2[r-1]);
else if(r==L)
printf("%d\n",a2[r]-a2[l-1]);
else if((r-l)==1)
printf("%d\n",a2[l]-a2[l-1]);
else
printf("%d\n",c);
}
return 0;
}
| |
Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.You've got string s = s1s2... sn (n is the length of the string), consisting only of characters "." and "#" and m queries. Each query is described by a pair of integers li, ri (1 ≤ li < ri ≤ n). The answer to the query li, ri is the number of such integers i (li ≤ i < ri), that si = si + 1.Ilya the Lion wants to help his friends but is there anyone to help him? Help Ilya, solve the problem. | Print m integers — the answers to the queries in the order in which they are given in the input. | C | b30e09449309b999473e4be6643d68cd | 5612b68610e2be22e86dac3d642b295d | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"dp",
"implementation"
] | 1369927800 | ["......\n4\n3 4\n2 3\n1 6\n2 6", "#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line contains string s of length n (2 ≤ n ≤ 105). It is guaranteed that the given string only consists of characters "." and "#". The next line contains integer m (1 ≤ m ≤ 105) — the number of queries. Each of the next m lines contains the description of the corresponding query. The i-th line contains integers li, ri (1 ≤ li < ri ≤ n). | ["1\n1\n5\n4", "1\n1\n2\n2\n0"] | #include "stdio.h"
#include "string.h"
int main() {
char str[100005];
scanf("%s",str);
int len=strlen(str);
int val[len-1];
for(int i=0;i<len-1;i++){
if(i==0){
val[i]=(int)(str[i]==str[i+1]);
}
else{
val[i]=val[i-1]+(int)(str[i]==str[i+1]);
}
}
int n;
scanf("%d",&n);
for(int i=0;i<n;i++){
int l,r;
scanf("%d %d",&l,&r);
printf("%d\n",val[r-2]-val[l-1]+(int)(str[l-1]==str[l]));
}
return 0;
}
| |
Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.You've got string s = s1s2... sn (n is the length of the string), consisting only of characters "." and "#" and m queries. Each query is described by a pair of integers li, ri (1 ≤ li < ri ≤ n). The answer to the query li, ri is the number of such integers i (li ≤ i < ri), that si = si + 1.Ilya the Lion wants to help his friends but is there anyone to help him? Help Ilya, solve the problem. | Print m integers — the answers to the queries in the order in which they are given in the input. | C | b30e09449309b999473e4be6643d68cd | 9903bb5902546cbbda43515166c0f2fb | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"dp",
"implementation"
] | 1369927800 | ["......\n4\n3 4\n2 3\n1 6\n2 6", "#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line contains string s of length n (2 ≤ n ≤ 105). It is guaranteed that the given string only consists of characters "." and "#". The next line contains integer m (1 ≤ m ≤ 105) — the number of queries. Each of the next m lines contains the description of the corresponding query. The i-th line contains integers li, ri (1 ≤ li < ri ≤ n). | ["1\n1\n5\n4", "1\n1\n2\n2\n0"] | #include<stdio.h>
#include<string.h>
int main ()
{
int m,n,l,r,i,count=0;
char s[100000];
scanf("%s",s);
int a[100000]={0};
//n is the length of the array of string
n=strlen(s);
scanf("%d",&m);
for(i=0;i<n-1;i++)
{
if(s[i]==s[i+1])
count++;
a[i+1]=count; //why i+1
}
int res=0;
for(i=1;i<=m;i++)
{
//m is the number of cases
scanf("%d%d",&l,&r);
res=a[r-1]-a[l-1];
printf("%d\n",res);
}
return 0;
}
| |
Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.You've got string s = s1s2... sn (n is the length of the string), consisting only of characters "." and "#" and m queries. Each query is described by a pair of integers li, ri (1 ≤ li < ri ≤ n). The answer to the query li, ri is the number of such integers i (li ≤ i < ri), that si = si + 1.Ilya the Lion wants to help his friends but is there anyone to help him? Help Ilya, solve the problem. | Print m integers — the answers to the queries in the order in which they are given in the input. | C | b30e09449309b999473e4be6643d68cd | 59c91d299fadb27f97adaa0cf121c30b | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"dp",
"implementation"
] | 1369927800 | ["......\n4\n3 4\n2 3\n1 6\n2 6", "#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line contains string s of length n (2 ≤ n ≤ 105). It is guaranteed that the given string only consists of characters "." and "#". The next line contains integer m (1 ≤ m ≤ 105) — the number of queries. Each of the next m lines contains the description of the corresponding query. The i-th line contains integers li, ri (1 ≤ li < ri ≤ n). | ["1\n1\n5\n4", "1\n1\n2\n2\n0"] | #include<stdio.h>
#include<string.h>
int main(){
int arr[100005]={0},a,b,i,n,m,sum;
char str[100005];
scanf("%s",str);
n=strlen(str);
for(i=1;i<n;i++){
if(str[i-1]==str[i]){
arr[i]=arr[i-1]+1;
}else{
arr[i]=arr[i-1];
}
}
scanf("%d",&m);
while(m--){
scanf("%d %d",&a,&b);
printf("%d\n",arr[b-1]-arr[a-1]);
}
return 0;
} | |
Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.You've got string s = s1s2... sn (n is the length of the string), consisting only of characters "." and "#" and m queries. Each query is described by a pair of integers li, ri (1 ≤ li < ri ≤ n). The answer to the query li, ri is the number of such integers i (li ≤ i < ri), that si = si + 1.Ilya the Lion wants to help his friends but is there anyone to help him? Help Ilya, solve the problem. | Print m integers — the answers to the queries in the order in which they are given in the input. | C | b30e09449309b999473e4be6643d68cd | e586249d1bb7db7cb7c48dc3124b0af3 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"dp",
"implementation"
] | 1369927800 | ["......\n4\n3 4\n2 3\n1 6\n2 6", "#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line contains string s of length n (2 ≤ n ≤ 105). It is guaranteed that the given string only consists of characters "." and "#". The next line contains integer m (1 ≤ m ≤ 105) — the number of queries. Each of the next m lines contains the description of the corresponding query. The i-th line contains integers li, ri (1 ≤ li < ri ≤ n). | ["1\n1\n5\n4", "1\n1\n2\n2\n0"] | #include<stdio.h>
#include<string.h>
int main()
{
char a[100005];
long len,l,r,i,m,b[100005],cnt=0;
scanf("%s",a);
scanf("%ld",&m);
len=strlen(a);
for(i=0;i<(len-1);i++)
{
if(a[i]==a[i+1])
cnt++;
b[i+1]=cnt;
}
while(m--)
{
scanf("%ld%ld",&l,&r);
printf("%ld\n",b[r-1]-b[l-1]);
}
return 0;
} | |
Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.You've got string s = s1s2... sn (n is the length of the string), consisting only of characters "." and "#" and m queries. Each query is described by a pair of integers li, ri (1 ≤ li < ri ≤ n). The answer to the query li, ri is the number of such integers i (li ≤ i < ri), that si = si + 1.Ilya the Lion wants to help his friends but is there anyone to help him? Help Ilya, solve the problem. | Print m integers — the answers to the queries in the order in which they are given in the input. | C | b30e09449309b999473e4be6643d68cd | 3d33462e66a69ce13af6c5b9d7648327 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"dp",
"implementation"
] | 1369927800 | ["......\n4\n3 4\n2 3\n1 6\n2 6", "#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line contains string s of length n (2 ≤ n ≤ 105). It is guaranteed that the given string only consists of characters "." and "#". The next line contains integer m (1 ≤ m ≤ 105) — the number of queries. Each of the next m lines contains the description of the corresponding query. The i-th line contains integers li, ri (1 ≤ li < ri ≤ n). | ["1\n1\n5\n4", "1\n1\n2\n2\n0"] | #include <stdio.h>
#include <string.h>
#define MX 100005
int main()
{
char s[MX];
scanf("%s", s);
int n = strlen(s), ps[MX] = {0}, j = 2, q;
for (int i = 0; i < n; ++i, ++j) {
ps[j] = ps[j-1];
if (s[i] == s[i+1]) ps[j]++;
}
scanf("%d", &q);
for (int i = 0; i < q; ++i) {
int a, b;
scanf("%d%d", &a, &b);
printf("%d\n", ps[b]-ps[a]);
}
} | |
Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.You've got string s = s1s2... sn (n is the length of the string), consisting only of characters "." and "#" and m queries. Each query is described by a pair of integers li, ri (1 ≤ li < ri ≤ n). The answer to the query li, ri is the number of such integers i (li ≤ i < ri), that si = si + 1.Ilya the Lion wants to help his friends but is there anyone to help him? Help Ilya, solve the problem. | Print m integers — the answers to the queries in the order in which they are given in the input. | C | b30e09449309b999473e4be6643d68cd | 316b6fdcb70b5c8a8ffe1ff91d682893 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"dp",
"implementation"
] | 1369927800 | ["......\n4\n3 4\n2 3\n1 6\n2 6", "#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line contains string s of length n (2 ≤ n ≤ 105). It is guaranteed that the given string only consists of characters "." and "#". The next line contains integer m (1 ≤ m ≤ 105) — the number of queries. Each of the next m lines contains the description of the corresponding query. The i-th line contains integers li, ri (1 ≤ li < ri ≤ n). | ["1\n1\n5\n4", "1\n1\n2\n2\n0"] | #include <stdio.h>
#include <string.h>
#define MX 100005
int main()
{
char s[MX];
gets(s);
int n = strlen(s), ps[MX] = {0}, j = 2, q;
for (int i = 0; i < n; ++i, ++j) {
ps[j] = ps[j-1];
if (s[i] == s[i+1]) ps[j]++;
}
scanf("%d", &q);
for (int i = 0; i < q; ++i) {
int a, b;
scanf("%d%d", &a, &b);
printf("%d\n", ps[b]-ps[a]);
}
} | |
Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.You've got string s = s1s2... sn (n is the length of the string), consisting only of characters "." and "#" and m queries. Each query is described by a pair of integers li, ri (1 ≤ li < ri ≤ n). The answer to the query li, ri is the number of such integers i (li ≤ i < ri), that si = si + 1.Ilya the Lion wants to help his friends but is there anyone to help him? Help Ilya, solve the problem. | Print m integers — the answers to the queries in the order in which they are given in the input. | C | b30e09449309b999473e4be6643d68cd | 6c8908ad5af69b37210efd99c10856e0 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"dp",
"implementation"
] | 1369927800 | ["......\n4\n3 4\n2 3\n1 6\n2 6", "#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line contains string s of length n (2 ≤ n ≤ 105). It is guaranteed that the given string only consists of characters "." and "#". The next line contains integer m (1 ≤ m ≤ 105) — the number of queries. Each of the next m lines contains the description of the corresponding query. The i-th line contains integers li, ri (1 ≤ li < ri ≤ n). | ["1\n1\n5\n4", "1\n1\n2\n2\n0"] | #include <stdio.h>
#include <string.h>
int main(void){
char s[100001];
int pos1,pos2, queries;
int answers=0;
int ans[100001];
scanf("%s", s);
scanf("%d", &queries);
int length = strlen(s);
for(int j=0;j<length-1;j++){
if(s[j]==s[j+1]){
answers+=1;
}
ans[j+1]=answers;
}
for(int i=0; i<queries; i++){
scanf("%d %d", &pos1, &pos2);
printf("%d\n", ans[pos2-1]-ans[pos1-1]);
}
}
| |
For the multiset of positive integers $$$s=\{s_1,s_2,\dots,s_k\}$$$, define the Greatest Common Divisor (GCD) and Least Common Multiple (LCM) of $$$s$$$ as follow: $$$\gcd(s)$$$ is the maximum positive integer $$$x$$$, such that all integers in $$$s$$$ are divisible on $$$x$$$. $$$\textrm{lcm}(s)$$$ is the minimum positive integer $$$x$$$, that divisible on all integers from $$$s$$$.For example, $$$\gcd(\{8,12\})=4,\gcd(\{12,18,6\})=6$$$ and $$$\textrm{lcm}(\{4,6\})=12$$$. Note that for any positive integer $$$x$$$, $$$\gcd(\{x\})=\textrm{lcm}(\{x\})=x$$$.Orac has a sequence $$$a$$$ with length $$$n$$$. He come up with the multiset $$$t=\{\textrm{lcm}(\{a_i,a_j\})\ |\ i<j\}$$$, and asked you to find the value of $$$\gcd(t)$$$ for him. In other words, you need to calculate the GCD of LCMs of all pairs of elements in the given sequence. | Print one integer: $$$\gcd(\{\textrm{lcm}(\{a_i,a_j\})\ |\ i<j\})$$$. | C | 3634a3367a1f05d1b3e8e4369e8427fb | 80717517c41326818f3b1f3bd1fa5b06 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"number theory",
"math"
] | 1589286900 | ["2\n1 1", "4\n10 24 40 80", "10\n540 648 810 648 720 540 594 864 972 648"] | NoteFor the first example, $$$t=\{\textrm{lcm}(\{1,1\})\}=\{1\}$$$, so $$$\gcd(t)=1$$$.For the second example, $$$t=\{120,40,80,120,240,80\}$$$, and it's not hard to see that $$$\gcd(t)=40$$$. | PASSED | 1,600 | standard input | 3 seconds | The first line contains one integer $$$n\ (2\le n\le 100\,000)$$$. The second line contains $$$n$$$ integers, $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 200\,000$$$). | ["1", "40", "54"] | #include<stdio.h>
long long int prime(long long int n)
{
if (n < 2)
return 0;
long long int i;
for (i = 2; i * i <= n; i++)
if (n % i == 0)
return i;
return n;
}
int main()
{
int n;
scanf("%d", &n);
int i;
long long int a[100005];
for (i = 0; i < n; i++)
scanf("%lld", &a[i]);
long long int ans = 1;
long long int p, q = a[0] * a[1];
long long int c, m1, m2;
while (q > 1)
{
p = prime(q);
m1 = m2 = -1;
for (i = 0; i < n; i++)
{
c = 0;
while (a[i] % p == 0)
{
c++;
a[i] /= p;
}
if (m1 < 0 || c < m1)
{
m2 = m1;
m1 = c;
}
else if (m2 < 0 || c < m2)
m2 = c;
}
for (m1 = 0; m1 < m2; m1++)
ans *= p;
q = a[0] * a[1];
}
printf("%lld\n", ans);
return 0;
} | |
For the multiset of positive integers $$$s=\{s_1,s_2,\dots,s_k\}$$$, define the Greatest Common Divisor (GCD) and Least Common Multiple (LCM) of $$$s$$$ as follow: $$$\gcd(s)$$$ is the maximum positive integer $$$x$$$, such that all integers in $$$s$$$ are divisible on $$$x$$$. $$$\textrm{lcm}(s)$$$ is the minimum positive integer $$$x$$$, that divisible on all integers from $$$s$$$.For example, $$$\gcd(\{8,12\})=4,\gcd(\{12,18,6\})=6$$$ and $$$\textrm{lcm}(\{4,6\})=12$$$. Note that for any positive integer $$$x$$$, $$$\gcd(\{x\})=\textrm{lcm}(\{x\})=x$$$.Orac has a sequence $$$a$$$ with length $$$n$$$. He come up with the multiset $$$t=\{\textrm{lcm}(\{a_i,a_j\})\ |\ i<j\}$$$, and asked you to find the value of $$$\gcd(t)$$$ for him. In other words, you need to calculate the GCD of LCMs of all pairs of elements in the given sequence. | Print one integer: $$$\gcd(\{\textrm{lcm}(\{a_i,a_j\})\ |\ i<j\})$$$. | C | 3634a3367a1f05d1b3e8e4369e8427fb | 7d0b021a3fc8050de228c0e1d5238a94 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"number theory",
"math"
] | 1589286900 | ["2\n1 1", "4\n10 24 40 80", "10\n540 648 810 648 720 540 594 864 972 648"] | NoteFor the first example, $$$t=\{\textrm{lcm}(\{1,1\})\}=\{1\}$$$, so $$$\gcd(t)=1$$$.For the second example, $$$t=\{120,40,80,120,240,80\}$$$, and it's not hard to see that $$$\gcd(t)=40$$$. | PASSED | 1,600 | standard input | 3 seconds | The first line contains one integer $$$n\ (2\le n\le 100\,000)$$$. The second line contains $$$n$$$ integers, $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 200\,000$$$). | ["1", "40", "54"] | #include <stdio.h>
#include <stdlib.h>
long long int gcd(long long int a, long long int b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
int main()
{
long long int n;
scanf("%lld", &n);
long long int a[n];
long long int i;
for ( i = 0; i < n; ++i )
{
scanf("%lld", &a[i]);
}
long long int pref[n];
long long int suff[n];
pref[0] = a[0];
for ( i = 1; i < n; ++i )
{
pref[i] = gcd(pref[i-1],a[i]);
}
suff[n-1] = a[n-1];
for ( i = n-2; i >= 0; --i )
{
suff[i] = gcd(suff[i+1],a[i]);
}
long long int d[n];
d[0] = suff[1];
d[n-1] = pref[n-2];
for ( i = 1; i < n-1; ++i )
{
d[i] = gcd(pref[i-1],suff[i+1]);
}
long long int sol;
sol = d[0]*d[1]/gcd(d[0],d[1]);
for ( i = 2; i < n; ++i )
{
sol = sol*d[i]/gcd(sol,d[i]);
}
/*
for ( i = 0; i < n; ++i )
{
printf("%lld ", pref[i]);
}
printf("\n");
for ( i = 0; i < n; ++i )
{
printf("%lld ", suff[i]);
}
printf("\n");
for ( i = 0; i < n; ++i )
{
printf("%lld ", d[i]);
}
printf("\n");
*/
printf("%lld\n", sol);
//system("pause");
} | |
For the multiset of positive integers $$$s=\{s_1,s_2,\dots,s_k\}$$$, define the Greatest Common Divisor (GCD) and Least Common Multiple (LCM) of $$$s$$$ as follow: $$$\gcd(s)$$$ is the maximum positive integer $$$x$$$, such that all integers in $$$s$$$ are divisible on $$$x$$$. $$$\textrm{lcm}(s)$$$ is the minimum positive integer $$$x$$$, that divisible on all integers from $$$s$$$.For example, $$$\gcd(\{8,12\})=4,\gcd(\{12,18,6\})=6$$$ and $$$\textrm{lcm}(\{4,6\})=12$$$. Note that for any positive integer $$$x$$$, $$$\gcd(\{x\})=\textrm{lcm}(\{x\})=x$$$.Orac has a sequence $$$a$$$ with length $$$n$$$. He come up with the multiset $$$t=\{\textrm{lcm}(\{a_i,a_j\})\ |\ i<j\}$$$, and asked you to find the value of $$$\gcd(t)$$$ for him. In other words, you need to calculate the GCD of LCMs of all pairs of elements in the given sequence. | Print one integer: $$$\gcd(\{\textrm{lcm}(\{a_i,a_j\})\ |\ i<j\})$$$. | C | 3634a3367a1f05d1b3e8e4369e8427fb | 52aa8be6ed1780eb90e81480b7cb686b | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"number theory",
"math"
] | 1589286900 | ["2\n1 1", "4\n10 24 40 80", "10\n540 648 810 648 720 540 594 864 972 648"] | NoteFor the first example, $$$t=\{\textrm{lcm}(\{1,1\})\}=\{1\}$$$, so $$$\gcd(t)=1$$$.For the second example, $$$t=\{120,40,80,120,240,80\}$$$, and it's not hard to see that $$$\gcd(t)=40$$$. | PASSED | 1,600 | standard input | 3 seconds | The first line contains one integer $$$n\ (2\le n\le 100\,000)$$$. The second line contains $$$n$$$ integers, $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 200\,000$$$). | ["1", "40", "54"] | #include <stdio.h>
typedef long long int ll;
ll gcd(ll a,ll b){
return b==0?a:gcd(b,a%b);
}
ll lcm(ll a,ll b){
ll t=gcd(a,b);
return ((a*b)/t);
}
int main()
{
ll n,count[200001],net,i;
scanf("%lld",&n);
ll a[n],hcf=1;
for(int i=0;i<n;i++)
scanf("%lld",&a[i]);
for(int i=1;i<200001;i++)
count[i]=0;
for(ll j=0;j<n;j++)
{
for(i=1;i<a[j]/i;i++)
{
if(a[j]%i==0)
{
count[i]++;
count[(a[j]/i)]++;
}
}
if(i*i==a[j])
count[i]++;
}
for(ll i=1;i<200001;i++)
{
if(count[i]>=n-1)
hcf=lcm(hcf,i);
}
printf("%lld",hcf);
} | |
For the multiset of positive integers $$$s=\{s_1,s_2,\dots,s_k\}$$$, define the Greatest Common Divisor (GCD) and Least Common Multiple (LCM) of $$$s$$$ as follow: $$$\gcd(s)$$$ is the maximum positive integer $$$x$$$, such that all integers in $$$s$$$ are divisible on $$$x$$$. $$$\textrm{lcm}(s)$$$ is the minimum positive integer $$$x$$$, that divisible on all integers from $$$s$$$.For example, $$$\gcd(\{8,12\})=4,\gcd(\{12,18,6\})=6$$$ and $$$\textrm{lcm}(\{4,6\})=12$$$. Note that for any positive integer $$$x$$$, $$$\gcd(\{x\})=\textrm{lcm}(\{x\})=x$$$.Orac has a sequence $$$a$$$ with length $$$n$$$. He come up with the multiset $$$t=\{\textrm{lcm}(\{a_i,a_j\})\ |\ i<j\}$$$, and asked you to find the value of $$$\gcd(t)$$$ for him. In other words, you need to calculate the GCD of LCMs of all pairs of elements in the given sequence. | Print one integer: $$$\gcd(\{\textrm{lcm}(\{a_i,a_j\})\ |\ i<j\})$$$. | C | 3634a3367a1f05d1b3e8e4369e8427fb | 9462af841c938c97f657ed4201bb396d | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"number theory",
"math"
] | 1589286900 | ["2\n1 1", "4\n10 24 40 80", "10\n540 648 810 648 720 540 594 864 972 648"] | NoteFor the first example, $$$t=\{\textrm{lcm}(\{1,1\})\}=\{1\}$$$, so $$$\gcd(t)=1$$$.For the second example, $$$t=\{120,40,80,120,240,80\}$$$, and it's not hard to see that $$$\gcd(t)=40$$$. | PASSED | 1,600 | standard input | 3 seconds | The first line contains one integer $$$n\ (2\le n\le 100\,000)$$$. The second line contains $$$n$$$ integers, $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 200\,000$$$). | ["1", "40", "54"] | #include <stdio.h>
long long A[100001];
int C[200001];
long long LCM(long long a, long long b)
{
long long c;
long long r = a * b;
while (b)
{
c = a % b;
a = b;
b = c;
}
r /= a;
return r;
}
int main()
{
int i;
long long a;
int t;
int temp;
int n;
long long R;
scanf("%d", &n);
for (i = 1; i <= n; i++)
{
scanf("%I64d", &A[i]);
}
for (i = 1; i <= 200000; i++)
{
C[i] = 0;
}
for (i = 1; i <= n; i++)
{
for (t = 1; t * t < A[i]; t++)
{
if (A[i] % t == 0)
{
C[t]++;
temp = A[i] / t;
C[temp]++;
}
}
if (t * t == A[i])
{
C[t]++;
}
}
R = 1;
for (a = 1; a <= 200000; a++)
{
if (C[a] >= n - 1)
{
R = LCM(R, a);
}
}
printf("%I64d", R);
return 0;
} | |
For the multiset of positive integers $$$s=\{s_1,s_2,\dots,s_k\}$$$, define the Greatest Common Divisor (GCD) and Least Common Multiple (LCM) of $$$s$$$ as follow: $$$\gcd(s)$$$ is the maximum positive integer $$$x$$$, such that all integers in $$$s$$$ are divisible on $$$x$$$. $$$\textrm{lcm}(s)$$$ is the minimum positive integer $$$x$$$, that divisible on all integers from $$$s$$$.For example, $$$\gcd(\{8,12\})=4,\gcd(\{12,18,6\})=6$$$ and $$$\textrm{lcm}(\{4,6\})=12$$$. Note that for any positive integer $$$x$$$, $$$\gcd(\{x\})=\textrm{lcm}(\{x\})=x$$$.Orac has a sequence $$$a$$$ with length $$$n$$$. He come up with the multiset $$$t=\{\textrm{lcm}(\{a_i,a_j\})\ |\ i<j\}$$$, and asked you to find the value of $$$\gcd(t)$$$ for him. In other words, you need to calculate the GCD of LCMs of all pairs of elements in the given sequence. | Print one integer: $$$\gcd(\{\textrm{lcm}(\{a_i,a_j\})\ |\ i<j\})$$$. | C | 3634a3367a1f05d1b3e8e4369e8427fb | 8d1e3bd05ea6b64f35a39cc7aa8ac442 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"number theory",
"math"
] | 1589286900 | ["2\n1 1", "4\n10 24 40 80", "10\n540 648 810 648 720 540 594 864 972 648"] | NoteFor the first example, $$$t=\{\textrm{lcm}(\{1,1\})\}=\{1\}$$$, so $$$\gcd(t)=1$$$.For the second example, $$$t=\{120,40,80,120,240,80\}$$$, and it's not hard to see that $$$\gcd(t)=40$$$. | PASSED | 1,600 | standard input | 3 seconds | The first line contains one integer $$$n\ (2\le n\le 100\,000)$$$. The second line contains $$$n$$$ integers, $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 200\,000$$$). | ["1", "40", "54"] | #include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<stdbool.h>
#include<assert.h>
typedef long long ll;
typedef long double ld;
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define rrep(i,l,r)for(ll i=(l);i>=(r);i--)
#define INF (1LL<<60)
#define MOD1 1000000007
#define MOD2 998244353
#define MAX_N (1 << 17)
#define YES printf("Yes\n")
#define NO printf("No\n")
#define PN printf("\n")
#define charsize 100005 //10^5+5
#define PI 3.141592653589793238
void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a= c;}
void cin(ll *n){ scanf("%lld",&(*n)); }
void cin2(ll *a, ll *b){ scanf("%lld%lld",&(*a),&(*b)); }
void cin3(ll *a, ll *b, ll *c){ scanf("%lld%lld%lld",&(*a),&(*b),&(*c)); }
ll max2(ll a,ll b){return a>=b?a:b;}
ll min2(ll a,ll b){return a>=b?b:a;}
ll min3(ll a, ll b, ll c){return (a<=b && a<=c) ? a : b<=c ? b : c;}
ll max3(ll a, ll b, ll c){return (a>=b && a>=c) ? a : b>=c ? b : c;}
ll minn(ll n, ll a[n]){ll b=INF;rep(i,0,n) b=min2(b,a[i]);return b;}
ll maxn(ll n, ll a[n]){ll b=-INF;rep(i,0,n) b=max2(b,a[i]);return b;}
ll ABS(ll a){return a>=0?a:(-a);}
ll POW(ll a, ll b){ll c=1;rep(i,0,b) c*=a;return c;}
double POW_d(double a, double b){double c=1;rep(i,0,b) c*=a;return c;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll mod_MOD1(ll n){n+= n<0?((-n)/MOD1+1)*MOD1:0; return n%=MOD1;}
ll mod_p(ll n ,ll p){n+= n<0?((-n)/p+1)*p:0; return n%=p;}
ll change_into_num(char s[] , ll len, ll p){ return !p ? 0 : POW(10,p-1)*(s[len-p]-'0') + change_into_num(s,len,p-1); }
void lr_lower( int *l, int *r, ll am, ll val , int type ){ (type<3) ? ( am < val ? ( *l = (*l+*r)/2 ) : ( *r= (*l+*r)/2 ) ) : ( am <= val ? ( *l = (*l+*r)/2 ) : ( *r= (*l+*r)/2 ) ); }
void lr_upper( int *l, int *r, ll am, ll val , int type ){ (type<3) ? ( am <= val ? ( *l = (*l+*r)/2 ) : ( *r= (*l+*r)/2 ) ) : ( am < val ? ( *l = (*l+*r)/2 ) : ( *r= (*l+*r)/2 ) ); }
int cmp_lower( ll a, ll b, int type ){ return (type==1) ? ( a==b ? 1 : 0 ) : (type==2) ? ( a>=b ? 1 : 0 ) : ( a>b ? 1 : 0 ) ; }
int cmp_upper( ll a, ll b, int type ){ return (type==1) ? ( a==b ? 1 : 0 ) : (type==2) ? ( a<=b ? 1 : 0 ) : ( a<b ? 1 : 0 ) ; }
// return smallest p which meets a[p]==val :1 >=:2 >:3
ll lower_bound( ll a[], int l, int r, ll val , int type ){ while(r-l>1) lr_lower(&l,&r,a[ (l+r)/2 ],val,type); return cmp_lower(a[l],val,type) ? l : cmp_lower(a[r],val,type) ? r : -1; }
// return biggest p which meets a[p]==val :1 <=:2 <:3
ll upper_bound( ll a[], int l, int r, ll val , int type ){ while(r-l>1) lr_upper(&l,&r,a[ (l+r)/2 ],val,type); return cmp_upper(a[r],val,type) ? r : cmp_upper(a[l],val,type) ? l : -1; }
// count i which meets ai==x
ll count(ll a[], int l, int r, ll x){ int p = lower_bound(a,l,r,x,1); return p==-1 ? 0 : upper_bound(a,p,r,x,1)-p+1; }
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
int cmp_string( const void * a , const void * b ) { return strcmp( (char *)a , (char *)b ); } // qsort((void*)s,n,sizeof(s[0]),int_sort );
int cmp_char(const void * a, const void * b) { return *(char *)a - *(char *)b;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
void sort_string(int n,int size,char s[][size]){ qsort( (void*)s , n , sizeof(s[0]) , cmp_string ); }
void sort_char(char *s){ qsort( (void *)s , strlen(s) , sizeof(char) , cmp_char ); }
ll unique_string(ll n ,ll size, char s[][size]){ ll ans=1; rep(i,1,n) if( strcmp(s[i],s[i-1]) ) ans++; return ans; }
ll unique_num(ll n , ll a[]){ ll ans=1; rep(i,1,n) if( a[i]!=a[i-1] ) ans++; return ans; }
typedef struct{ ll a , b;}fr;
int cmp1( const void *p, const void *q ) { return ((fr*)p) ->a - ((fr*)q)->a;}
int cmp2( const void *p, const void *q ) { return ((fr*)q) ->a - ((fr*)p)->a;}
void strsortup(fr*a,int n){qsort(a,n,sizeof(fr),cmp1);}
void strsortdown(fr*a,int n){qsort(a,n,sizeof(fr),cmp2);}
// /*----------------------priorityqueue(2次元配列)-----------------------------------------------------------*/
// // kind = max?1:0
// ll HeapValue(ll a){ return a?-INF:INF; }
// ll Heapcmp(ll a, ll b, ll kind){ return kind ? (a<b?1:0) : (a>b?1:0); }
// ll heap2[1500][10];
// void pushHeap(ll set, ll val, ll len , ll kind){
// ll i=len; heap2[set][i]=val;
// while(i!=0){
// if( Heapcmp( heap2[set][i], heap2[set][(i-1)/2] , ABS(kind-1) ) ) swap(&heap2[set][i],&heap2[set][(i-1)/2]);
// i--;i/=2;
// }
// }
// void popHeap(ll set, ll *val, ll len, ll kind){
// ll i=0; *val=heap2[set][0]; heap2[set][0]=HeapValue(kind);
// swap(&heap2[set][0],&heap2[set][len-1]);
// while(len>i*2+1){
// if(i*2+2<len && Heapcmp(heap2[set][i],heap2[set][i*2+2],kind) && Heapcmp(heap2[set][i*2+1],heap2[set][i*2+2],kind) ){
// swap(&heap2[set][i],&heap2[set][i*2+2]);
// i*=2;i+=2;
// }else{
// if( Heapcmp(heap2[set][i],heap2[set][i*2+1],kind) ){
// swap(&heap2[set][i],&heap2[set][i*2+1]);
// i*=2;i++;
// }else break;
// }
// }
// }
// /*---------------------------------------------------------------------------------*/
ll pri[1500],len[1500],jud[1500];
ll pri_cnt[1500][2];
ll p=0;
ll judge_prime(ll n){
if(n==2) return 1;
if(n==1 || n%2==0) return 0;
ll a=sqrt(n); if(a%2==0) a--;
repp(i,3,a+1,2){if(n%i==0) return 0;}
return 1;
}
ll super_unique[5][2];
int main(void){
// fgets(s,sizeof(s),stdin);
// char ;
ll n;
ll ans=1;
cin(&n);
// if(n==2){
// printf("%lld\n",lcm)
// }
pri[p]=2;
pri_cnt[2][0]=-1;
pri_cnt[2][1]=-1;
p++;
repp(i,3,1500,2){
if(!judge_prime(i)) continue;
pri[p]=i;
pri_cnt[i][0]=-1;
pri_cnt[i][1]=-1;
p++;
}
ll a;
rep(i,0,n){
cin(&a);
// printf("%lld ||",a);
rep(j,0,p){
ll d=0;
while(a%pri[j]==0){
a/=pri[j];
d++;
}
// printf("%lld %lld\n",d,pri_cnt[pri[j]][1]);
if(pri_cnt[pri[j]][0]==-1){
pri_cnt[pri[j]][0]=d;
}else if(pri_cnt[pri[j]][1]==-1){
pri_cnt[pri[j]][1]=d;
if( pri_cnt[pri[j]][0] > pri_cnt[pri[j]][1] ) swap(&pri_cnt[pri[j]][0],&pri_cnt[pri[j]][1]);
}else{
pri_cnt[pri[j]][1] = min2( pri_cnt[pri[j]][1],d );
if( pri_cnt[pri[j]][0] > pri_cnt[pri[j]][1] ) swap(&pri_cnt[pri[j]][0],&pri_cnt[pri[j]][1]);
}
}
if(a!=1){
rep(j,0,5){
if(super_unique[j][0]==a){
super_unique[j][1]++;
goto NEXT;
}
}
rep(j,0,5){
if( super_unique[j][0]==0 ){
super_unique[j][0]=a;
super_unique[j][1]=1;
break;
}
}
NEXT:;
}
rep(j,0,5){
// printf("%lld %lld\n",i,super_unique[j][1]);
if(super_unique[j][1]<i){
super_unique[j][0]=0;
super_unique[j][1]=0;
}
}
// PN;
// PN;
}
rep(i,0,p){
// printf("%lld %lld\n",pri[i],pri_cnt[pri[i]][1] );
ans*=POW(pri[i],pri_cnt[pri[i]][1] );
}
rep(i,0,5){
// printf("%lld ",super_unique[i][1]);
if(super_unique[i][1]){
ans*=super_unique[i][0];
}
}
printf("%lld\n",ans);
return 0;
}
| |
For the multiset of positive integers $$$s=\{s_1,s_2,\dots,s_k\}$$$, define the Greatest Common Divisor (GCD) and Least Common Multiple (LCM) of $$$s$$$ as follow: $$$\gcd(s)$$$ is the maximum positive integer $$$x$$$, such that all integers in $$$s$$$ are divisible on $$$x$$$. $$$\textrm{lcm}(s)$$$ is the minimum positive integer $$$x$$$, that divisible on all integers from $$$s$$$.For example, $$$\gcd(\{8,12\})=4,\gcd(\{12,18,6\})=6$$$ and $$$\textrm{lcm}(\{4,6\})=12$$$. Note that for any positive integer $$$x$$$, $$$\gcd(\{x\})=\textrm{lcm}(\{x\})=x$$$.Orac has a sequence $$$a$$$ with length $$$n$$$. He come up with the multiset $$$t=\{\textrm{lcm}(\{a_i,a_j\})\ |\ i<j\}$$$, and asked you to find the value of $$$\gcd(t)$$$ for him. In other words, you need to calculate the GCD of LCMs of all pairs of elements in the given sequence. | Print one integer: $$$\gcd(\{\textrm{lcm}(\{a_i,a_j\})\ |\ i<j\})$$$. | C | 3634a3367a1f05d1b3e8e4369e8427fb | 27d34659472e8fff7a0bb49b41b5ba5c | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"number theory",
"math"
] | 1589286900 | ["2\n1 1", "4\n10 24 40 80", "10\n540 648 810 648 720 540 594 864 972 648"] | NoteFor the first example, $$$t=\{\textrm{lcm}(\{1,1\})\}=\{1\}$$$, so $$$\gcd(t)=1$$$.For the second example, $$$t=\{120,40,80,120,240,80\}$$$, and it's not hard to see that $$$\gcd(t)=40$$$. | PASSED | 1,600 | standard input | 3 seconds | The first line contains one integer $$$n\ (2\le n\le 100\,000)$$$. The second line contains $$$n$$$ integers, $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 200\,000$$$). | ["1", "40", "54"] | #include<stdio.h>
long long gcd(long long x, long long y){
if(y==0) return x;
else return gcd(y,x%y);
}
main(){
int n;
scanf("%d",&n);
int arr[n];
for(int i=0;i<n;i++) scanf("%d",&arr[i]);
int pre[n];
int pos[n];
pre[0]=arr[0];
pos[n-1]=arr[n-1];
for(int i=1;i<n;i++){
pre[i]=gcd(arr[i],pre[i-1]);
}
for(int i=n-2;i>=0;i--){
pos[i]=gcd(arr[i],pos[i+1]);
}
long long ans;
for(int i=0;i<n;i++){
if(i==0){
long long temp=pos[1];
ans=(long long)temp;
}
else if(i==n-1){
long long temp=pre[n-2];
ans=(long long)ans*temp/(gcd(ans,(long long)temp));
}
else{
long long temp=gcd(pre[i-1],pos[i+1]);
ans=(long long)ans*temp/(gcd(ans,(long long)temp));
}
}
printf("%lld",ans);
} | |
For the multiset of positive integers $$$s=\{s_1,s_2,\dots,s_k\}$$$, define the Greatest Common Divisor (GCD) and Least Common Multiple (LCM) of $$$s$$$ as follow: $$$\gcd(s)$$$ is the maximum positive integer $$$x$$$, such that all integers in $$$s$$$ are divisible on $$$x$$$. $$$\textrm{lcm}(s)$$$ is the minimum positive integer $$$x$$$, that divisible on all integers from $$$s$$$.For example, $$$\gcd(\{8,12\})=4,\gcd(\{12,18,6\})=6$$$ and $$$\textrm{lcm}(\{4,6\})=12$$$. Note that for any positive integer $$$x$$$, $$$\gcd(\{x\})=\textrm{lcm}(\{x\})=x$$$.Orac has a sequence $$$a$$$ with length $$$n$$$. He come up with the multiset $$$t=\{\textrm{lcm}(\{a_i,a_j\})\ |\ i<j\}$$$, and asked you to find the value of $$$\gcd(t)$$$ for him. In other words, you need to calculate the GCD of LCMs of all pairs of elements in the given sequence. | Print one integer: $$$\gcd(\{\textrm{lcm}(\{a_i,a_j\})\ |\ i<j\})$$$. | C | 3634a3367a1f05d1b3e8e4369e8427fb | 1fde001ae46a3dc183331520872d28a5 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"number theory",
"math"
] | 1589286900 | ["2\n1 1", "4\n10 24 40 80", "10\n540 648 810 648 720 540 594 864 972 648"] | NoteFor the first example, $$$t=\{\textrm{lcm}(\{1,1\})\}=\{1\}$$$, so $$$\gcd(t)=1$$$.For the second example, $$$t=\{120,40,80,120,240,80\}$$$, and it's not hard to see that $$$\gcd(t)=40$$$. | PASSED | 1,600 | standard input | 3 seconds | The first line contains one integer $$$n\ (2\le n\le 100\,000)$$$. The second line contains $$$n$$$ integers, $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 200\,000$$$). | ["1", "40", "54"] | #include<stdio.h>
long long gcd(long long a,long long b)
{
return b==0?a:gcd(b,a%b);
}
int main()
{
long long b[100010];
long long n,lcm=0,gcd1=0;
long long a[100010];
scanf("%lld",&n);
for(int i=0;i<n;i++)
{
scanf("%lld",&a[i]);
}
for(long long j=n-1;j>=0;j--)
b[j]=gcd(b[j+1],a[j]);
for(int i=0;i<n;i++)
{
gcd1=gcd(a[i]*b[i+1]/gcd(a[i],b[i+1]),gcd1);
}
printf("%lld",gcd1);
return 0;
}
| |
For the multiset of positive integers $$$s=\{s_1,s_2,\dots,s_k\}$$$, define the Greatest Common Divisor (GCD) and Least Common Multiple (LCM) of $$$s$$$ as follow: $$$\gcd(s)$$$ is the maximum positive integer $$$x$$$, such that all integers in $$$s$$$ are divisible on $$$x$$$. $$$\textrm{lcm}(s)$$$ is the minimum positive integer $$$x$$$, that divisible on all integers from $$$s$$$.For example, $$$\gcd(\{8,12\})=4,\gcd(\{12,18,6\})=6$$$ and $$$\textrm{lcm}(\{4,6\})=12$$$. Note that for any positive integer $$$x$$$, $$$\gcd(\{x\})=\textrm{lcm}(\{x\})=x$$$.Orac has a sequence $$$a$$$ with length $$$n$$$. He come up with the multiset $$$t=\{\textrm{lcm}(\{a_i,a_j\})\ |\ i<j\}$$$, and asked you to find the value of $$$\gcd(t)$$$ for him. In other words, you need to calculate the GCD of LCMs of all pairs of elements in the given sequence. | Print one integer: $$$\gcd(\{\textrm{lcm}(\{a_i,a_j\})\ |\ i<j\})$$$. | C | 3634a3367a1f05d1b3e8e4369e8427fb | 1ab8973d495a7548d2f80ee71a52432c | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"number theory",
"math"
] | 1589286900 | ["2\n1 1", "4\n10 24 40 80", "10\n540 648 810 648 720 540 594 864 972 648"] | NoteFor the first example, $$$t=\{\textrm{lcm}(\{1,1\})\}=\{1\}$$$, so $$$\gcd(t)=1$$$.For the second example, $$$t=\{120,40,80,120,240,80\}$$$, and it's not hard to see that $$$\gcd(t)=40$$$. | PASSED | 1,600 | standard input | 3 seconds | The first line contains one integer $$$n\ (2\le n\le 100\,000)$$$. The second line contains $$$n$$$ integers, $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 200\,000$$$). | ["1", "40", "54"] | #include <stdio.h>
#include <stdbool.h>
typedef long long int ll;
int main() {
int n;
scanf("%d",&n);
int arr[n+10];
int freq[200010];
for(int i = 1; i<=200000; i++) {
freq[i] = 0;
}
for(int i = 1; i<=n; i++) {
scanf("%d",&arr[i]);
freq[arr[i]]++;
}
bool b[200010];
ll ans = 1;
for(int i = 0; i<200010; i++) b[i] = 0;
for(int i = 2; i <= 200000; i++){
if(b[i]) continue;
ll tmp = i;
ll prev = 1;
while(true) {
int cnt = 0;
for (ll j = tmp; j <= 200000; j += tmp) {
cnt += freq[j];
}
if(cnt<(n-1)) break;
prev = tmp;
tmp *= i;
}
for (ll j = i; j <= 200000; j += i) {
b[j]=1;
}
ans*= prev;
//printf("%lld\n",ans);
}
printf("%lld",ans);
return 0;
}
| |
Anya and Kirill are doing a physics laboratory work. In one of the tasks they have to measure some value n times, and then compute the average value to lower the error.Kirill has already made his measurements, and has got the following integer values: x1, x2, ..., xn. It is important that the values are close to each other, namely, the difference between the maximum value and the minimum value is at most 2.Anya does not want to make the measurements, however, she can't just copy the values from Kirill's work, because the error of each measurement is a random value, and this coincidence will be noted by the teacher. Anya wants to write such integer values y1, y2, ..., yn in her work, that the following conditions are met: the average value of x1, x2, ..., xn is equal to the average value of y1, y2, ..., yn; all Anya's measurements are in the same bounds as all Kirill's measurements, that is, the maximum value among Anya's values is not greater than the maximum value among Kirill's values, and the minimum value among Anya's values is not less than the minimum value among Kirill's values; the number of equal measurements in Anya's work and Kirill's work is as small as possible among options with the previous conditions met. Formally, the teacher goes through all Anya's values one by one, if there is equal value in Kirill's work and it is not strike off yet, he strikes off this Anya's value and one of equal values in Kirill's work. The number of equal measurements is then the total number of strike off values in Anya's work. Help Anya to write such a set of measurements that the conditions above are met. | In the first line print the minimum possible number of equal measurements. In the second line print n integers y1, y2, ..., yn — the values Anya should write. You can print the integers in arbitrary order. Keep in mind that the minimum value among Anya's values should be not less that the minimum among Kirill's values, and the maximum among Anya's values should be not greater than the maximum among Kirill's values. If there are multiple answers, print any of them. | C | dbbea6784cafdd4244f56729996e9187 | 4041f3f8ad05563a4b75a5bb6057c762 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"math"
] | 1520177700 | ["6\n-1 1 1 0 0 -1", "3\n100 100 101", "7\n-10 -9 -10 -8 -10 -9 -9"] | NoteIn the first example Anya can write zeros as here measurements results. The average value is then equal to the average value of Kirill's values, and there are only two equal measurements.In the second example Anya should write two values 100 and one value 101 (in any order), because it is the only possibility to make the average be the equal to the average of Kirill's values. Thus, all three measurements are equal.In the third example the number of equal measurements is 5. | PASSED | 1,700 | standard input | 1 second | The first line contains a single integer n (1 ≤ n ≤ 100 000) — the numeber of measurements made by Kirill. The second line contains a sequence of integers x1, x2, ..., xn ( - 100 000 ≤ xi ≤ 100 000) — the measurements made by Kirill. It is guaranteed that the difference between the maximum and minimum values among values x1, x2, ..., xn does not exceed 2. | ["2\n0 0 0 0 0 0", "3\n101 100 100", "5\n-10 -10 -9 -9 -9 -9 -9"] | #include <stdio.h>
#define SIZE 100000
static int x[SIZE];
static inline int min(int a, int b)
{
if (a < b)
return a;
return b;
}
static inline int max(int a, int b)
{
if (a > b)
return a;
return b;
}
static inline int abs(int a)
{
if (a < 0)
return -a;
return a;
}
int main(void)
{
int n, m, M, avg, err, i, mn, mx, a, pavg, pm, pM;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d", &x[i]);
if (i == 0) {
mn = mx = x[i];
}
if (x[i] < mn) {
mn = x[i];
}
if (x[i] > mx) {
mx = x[i];
}
}
if (mx - mn != 2) {
printf("%d\n", n);
for (i = 0; i < n; i++) {
printf("%d ", x[i]);
}
return 0;
}
avg = mn + 1;
m = M = a = 0;
for (i = 0; i < n; i++) {
if (x[i] == mn) {
m++;
} else if (x[i] == mx) {
M++;
} else if (x[i] == avg) {
a++;
}
}
if (a + min(m, max(0, m - M)) + min(M, max(0, M - m)) < a - a / 2 * 2 + m + M) {
pavg = a + 2 * min(M, m);
pm = max(0, m - M);
pM = max(0, M - m);
} else {
pm = m + a / 2;
pM = M + a / 2;
pavg = a - a / 2 * 2;
}
printf("%d\n", min(pavg, a) + min(m, pm) + min(M, pM));
for (i = 0; i < pavg; i++) {
printf("%d ", avg);
}
for (i = 0; i < pm; i++) {
printf("%d ", mn);
}
for (i = 0; i < pM; i++) {
printf("%d ", mx);
}
return 0;
}
| |
Anya and Kirill are doing a physics laboratory work. In one of the tasks they have to measure some value n times, and then compute the average value to lower the error.Kirill has already made his measurements, and has got the following integer values: x1, x2, ..., xn. It is important that the values are close to each other, namely, the difference between the maximum value and the minimum value is at most 2.Anya does not want to make the measurements, however, she can't just copy the values from Kirill's work, because the error of each measurement is a random value, and this coincidence will be noted by the teacher. Anya wants to write such integer values y1, y2, ..., yn in her work, that the following conditions are met: the average value of x1, x2, ..., xn is equal to the average value of y1, y2, ..., yn; all Anya's measurements are in the same bounds as all Kirill's measurements, that is, the maximum value among Anya's values is not greater than the maximum value among Kirill's values, and the minimum value among Anya's values is not less than the minimum value among Kirill's values; the number of equal measurements in Anya's work and Kirill's work is as small as possible among options with the previous conditions met. Formally, the teacher goes through all Anya's values one by one, if there is equal value in Kirill's work and it is not strike off yet, he strikes off this Anya's value and one of equal values in Kirill's work. The number of equal measurements is then the total number of strike off values in Anya's work. Help Anya to write such a set of measurements that the conditions above are met. | In the first line print the minimum possible number of equal measurements. In the second line print n integers y1, y2, ..., yn — the values Anya should write. You can print the integers in arbitrary order. Keep in mind that the minimum value among Anya's values should be not less that the minimum among Kirill's values, and the maximum among Anya's values should be not greater than the maximum among Kirill's values. If there are multiple answers, print any of them. | C | dbbea6784cafdd4244f56729996e9187 | 9475fa31dcb2f3a03b102b317a15d999 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"math"
] | 1520177700 | ["6\n-1 1 1 0 0 -1", "3\n100 100 101", "7\n-10 -9 -10 -8 -10 -9 -9"] | NoteIn the first example Anya can write zeros as here measurements results. The average value is then equal to the average value of Kirill's values, and there are only two equal measurements.In the second example Anya should write two values 100 and one value 101 (in any order), because it is the only possibility to make the average be the equal to the average of Kirill's values. Thus, all three measurements are equal.In the third example the number of equal measurements is 5. | PASSED | 1,700 | standard input | 1 second | The first line contains a single integer n (1 ≤ n ≤ 100 000) — the numeber of measurements made by Kirill. The second line contains a sequence of integers x1, x2, ..., xn ( - 100 000 ≤ xi ≤ 100 000) — the measurements made by Kirill. It is guaranteed that the difference between the maximum and minimum values among values x1, x2, ..., xn does not exceed 2. | ["2\n0 0 0 0 0 0", "3\n101 100 100", "5\n-10 -10 -9 -9 -9 -9 -9"] | #include <stdio.h>
#include <stdlib.h>
int main()
{
int n;
int *x;
int min,mid,max;
int nummin,nummid,nummax;
int i;
min = 200000;
max = -200000;
scanf("%d",&n);
x = (int *)malloc(sizeof(int)*n);
for (i=0;i<n;i++)
scanf("%d",x+i);
for (i=0;i<n;i++)
{
if (x[i]>max) max = x[i];
if (x[i]<min) min = x[i];
}
if (min==max)
{
printf("%d\n",n);
for (i=0;i<n;i++)
printf("%d ",min);
printf("\n");
return 0;
}
else if (max-min==1)
{
printf("%d\n",n);
for (i=0;i<n;i++)
printf("%d ",x[i]);
printf("\n");
return 0;
}
else
{
mid = min+1;
nummin = nummid = nummax = 0;
for (i=0;i<n;i++)
{
if (x[i]==min) nummin++;
else if (x[i]==max) nummax++;
else nummid++;
}
if (nummin<nummax)
{
if (nummid>2*nummin)
{
printf("%d\n",nummin+nummax+(nummid%2));
for (i=0;i<nummin;i++)
{
printf("%d ",min);
}
for (i=0;i<nummax;i++)
{
printf("%d ",max);
}
for (i=0;i<(nummid/2);i++)
{
printf("%d %d ",min,max);
}
if (nummid%2==1)
printf("%d\n",mid);
else
printf("\n");
return 0;
}
else
{
printf("%d\n",nummid+(nummax-nummin));
for (i=0;i<nummid;i++)
{
printf("%d ",mid);
}
for (i=0;i<nummin*2;i++)
{
printf("%d ",mid);
}
for (i=0;i<nummax-nummin;i++)
{
printf("%d ",max);
}
printf("\n");
}
}
else
{
if (nummid>2*nummax)
{
printf("%d\n",nummin+nummax+(nummid%2));
for (i=0;i<nummin;i++)
{
printf("%d ",min);
}
for (i=0;i<nummax;i++)
{
printf("%d ",max);
}
for (i=0;i<(nummid/2);i++)
{
printf("%d %d ",min,max);
}
if (nummid%2==1)
printf("%d\n",mid);
else
printf("\n");
return 0;
}
else
{
printf("%d\n",nummid+(nummin-nummax));
for (i=0;i<nummid;i++)
{
printf("%d ",mid);
}
for (i=0;i<nummax*2;i++)
{
printf("%d ",mid);
}
for (i=0;i<nummin-nummax;i++)
{
printf("%d ",min);
}
printf("\n");
}
}
}
return 0;
}
| |
We have a secret array. You don't know this array and you have to restore it. However, you know some facts about this array: The array consists of $$$n$$$ distinct positive (greater than $$$0$$$) integers. The array contains two elements $$$x$$$ and $$$y$$$ (these elements are known for you) such that $$$x < y$$$. If you sort the array in increasing order (such that $$$a_1 < a_2 < \ldots < a_n$$$), differences between all adjacent (consecutive) elements are equal (i.e. $$$a_2 - a_1 = a_3 - a_2 = \ldots = a_n - a_{n-1})$$$. It can be proven that such an array always exists under the constraints given below.Among all possible arrays that satisfy the given conditions, we ask you to restore one which has the minimum possible maximum element. In other words, you have to minimize $$$\max(a_1, a_2, \dots, a_n)$$$.You have to answer $$$t$$$ independent test cases. | For each test case, print the answer: $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the $$$i$$$-th element of the required array. If there are several answers, you can print any (it also means that the order of elements doesn't matter). It can be proven that such an array always exists under the given constraints. | C | ca9d97e731e86cf8223520f39ef5d945 | b308b4053f209eff9e2fd4210297fa01 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"number theory",
"brute force",
"math"
] | 1599230100 | ["5\n2 1 49\n5 20 50\n6 20 50\n5 3 8\n9 13 22"] | null | PASSED | 1,200 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$2 \le n \le 50$$$; $$$1 \le x < y \le 50$$$) — the length of the array and two elements that are present in the array, respectively. | ["1 49 \n20 40 30 50 10\n26 32 20 38 44 50 \n8 23 18 13 3 \n1 10 13 4 19 22 25 16 7"] | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int isprime(long long p)
{ int i; double max=sqrt(p);
for(i=2;i<=max;i++)
if(p%i==0)break;
if(i>max && p!=1)return 1;
return 0;
}
long long gcd(long long a,long long b)
{ long long i;
for(i=a<b?a:b;i>0;i--)
if((a%i==0)&&(b%i==0))break;
return i;
}
int comp(const void * a, const void * b)
{
return ( *(int*)a - *(int*)b );
}
int issame(int *a,int *b,int l) //checks if two arrays of same length are same after sorting them **
{ qsort(a,l,sizeof(int),comp);
qsort(b,l,sizeof(int),comp);
int i;
for(i=0; i<l; i++)
if(a[i]!=b[i]) break;
if(i==l)return 1;
return 0;
}
void swap(int *a, int *b)
{int x= *a;
*a= *b;
*b=x;
}
int arrmax(int *a, int l)
{ int i; int max= a[0];
for(i=1;i<l;i++)
if(a[i]>max)max=a[i];
return max;
}
int arrmin(int *a, int l)
{ int i; int min= a[0];
for(i=1;i<l;i++)
if(a[i]<min)min=a[i];
return min;
}
long long fact(int a)
{long long p=1;
while(a>0)
p*=a--;
return p;
}
int min(int a, int b)
{if(a>b) return b;
return a;}
int max(int a, int b)
{if(a<b) return b;
return a;}
void sieve( int*a, int n)
{ n--;
long long i,j;
for(i=2;i<=n;i++)
a[i]=0;
for(i=2;i<=n;i++)
if(!a[i])
for(j=i*i;j<=n;j+=i)
if(!a[j])a[j]++;
}
int main(void)
{
int t; scanf("%d",&t); while(t--)
{
int n,x,y,l,s,r;
scanf("%d %d %d",&n,&x,&y);
int i,j,d=y-x;
for(i=1;i <50; i++)
{
if(d%i==0)
{
l= d/i + 1;
if(l>n)continue;
else
{
r= x/i -((x%i)== 0);
if(l+r <= n) s=x%i;
else s= x-(n-l)*i;
if (s==0)s=i;
break;
}
}
}
for(j=1;j<=n;j++)
{
printf("%d ",s);
s+=i;
}
printf("\n");
}
return 0;
}
| |
We have a secret array. You don't know this array and you have to restore it. However, you know some facts about this array: The array consists of $$$n$$$ distinct positive (greater than $$$0$$$) integers. The array contains two elements $$$x$$$ and $$$y$$$ (these elements are known for you) such that $$$x < y$$$. If you sort the array in increasing order (such that $$$a_1 < a_2 < \ldots < a_n$$$), differences between all adjacent (consecutive) elements are equal (i.e. $$$a_2 - a_1 = a_3 - a_2 = \ldots = a_n - a_{n-1})$$$. It can be proven that such an array always exists under the constraints given below.Among all possible arrays that satisfy the given conditions, we ask you to restore one which has the minimum possible maximum element. In other words, you have to minimize $$$\max(a_1, a_2, \dots, a_n)$$$.You have to answer $$$t$$$ independent test cases. | For each test case, print the answer: $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the $$$i$$$-th element of the required array. If there are several answers, you can print any (it also means that the order of elements doesn't matter). It can be proven that such an array always exists under the given constraints. | C | ca9d97e731e86cf8223520f39ef5d945 | ca22805e338553ffd26e60ca8c0a2d59 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"number theory",
"brute force",
"math"
] | 1599230100 | ["5\n2 1 49\n5 20 50\n6 20 50\n5 3 8\n9 13 22"] | null | PASSED | 1,200 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$2 \le n \le 50$$$; $$$1 \le x < y \le 50$$$) — the length of the array and two elements that are present in the array, respectively. | ["1 49 \n20 40 30 50 10\n26 32 20 38 44 50 \n8 23 18 13 3 \n1 10 13 4 19 22 25 16 7"] | #include <stdio.h>
#include <limits.h>
int min(int a,int b)
{
if(a<=b)
return a;
else return b;
}
int main(void)
{
int t,sum;
scanf("%d",&t);
while(t--)
{
int n,x,y;
scanf("%d %d %d",&n,&x,&y);
if(n==2)
{
printf("%d %d\n",x,y);
continue;
}
int mix=INT_MAX,b,beda=INT_MAX;
for(int i=0;i<n;i++)
{
for(int j=i+1;j<n;j++)
{
sum=x;
if((y-x)%(j-i)!=0)
continue;
b=(y-x)/(j-i);
if(i!=0)
{
sum = x-(i-0)*b;
if(sum <=0)
continue;
}
for(int j=1;j<n;j++)
sum = sum + b;
mix= min(mix,sum);
beda = min(beda,b);
}
}
for(int i=n;i>0;i--)
{
printf("%d ",mix);
mix = mix - beda;
}
puts("");
}
return 0;
} | |
We have a secret array. You don't know this array and you have to restore it. However, you know some facts about this array: The array consists of $$$n$$$ distinct positive (greater than $$$0$$$) integers. The array contains two elements $$$x$$$ and $$$y$$$ (these elements are known for you) such that $$$x < y$$$. If you sort the array in increasing order (such that $$$a_1 < a_2 < \ldots < a_n$$$), differences between all adjacent (consecutive) elements are equal (i.e. $$$a_2 - a_1 = a_3 - a_2 = \ldots = a_n - a_{n-1})$$$. It can be proven that such an array always exists under the constraints given below.Among all possible arrays that satisfy the given conditions, we ask you to restore one which has the minimum possible maximum element. In other words, you have to minimize $$$\max(a_1, a_2, \dots, a_n)$$$.You have to answer $$$t$$$ independent test cases. | For each test case, print the answer: $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the $$$i$$$-th element of the required array. If there are several answers, you can print any (it also means that the order of elements doesn't matter). It can be proven that such an array always exists under the given constraints. | C | ca9d97e731e86cf8223520f39ef5d945 | 638e6c660e3dcca80e920849f50cc185 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"number theory",
"brute force",
"math"
] | 1599230100 | ["5\n2 1 49\n5 20 50\n6 20 50\n5 3 8\n9 13 22"] | null | PASSED | 1,200 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$2 \le n \le 50$$$; $$$1 \le x < y \le 50$$$) — the length of the array and two elements that are present in the array, respectively. | ["1 49 \n20 40 30 50 10\n26 32 20 38 44 50 \n8 23 18 13 3 \n1 10 13 4 19 22 25 16 7"] | #include <stdio.h>
#include <stdlib.h>
#include <limits.h>
int main(){
int t;
scanf("%d",&t);
for(int i = 0;i < t;i++){
int n,x,y;
scanf("%d %d %d",&n,&x,&y);
int *ans = (int *)malloc(sizeof(int)*n);
ans[n-1] = 2000000000;
for(int i = 0;i < n;i++){
for(int j = i+1;j<n;j++){
int *arr = (int *)malloc(sizeof(int)*n);
arr[i] = x;
arr[j] = y;
int diff = y-x;
if(diff%(j-i)!=0){
continue;
}
diff = diff/(j - i);
if(diff==0){
continue;
}
for(int k = i-1;k>=0;k--){
arr[k] = arr[k+1] - diff;
}
for(int k = i+1;k<n;k++){
arr[k] = arr[k-1] + diff;
}
int found = 0;
for(int k = 0;k < n;k++){
if(arr[k]<=0){
found = 0;
break;
}
if(arr[k]==y||arr[k] == x){
found++;
}
}
if(found ==2 && arr[n-1]<ans[n-1]){
for(int k = 0;k < n;k++){
ans[k] = arr[k];
}
}
}
}
for(int k = 0;k < n;k++){
printf("%d ",ans[k]);
}
printf("\n");
}
} | |
We have a secret array. You don't know this array and you have to restore it. However, you know some facts about this array: The array consists of $$$n$$$ distinct positive (greater than $$$0$$$) integers. The array contains two elements $$$x$$$ and $$$y$$$ (these elements are known for you) such that $$$x < y$$$. If you sort the array in increasing order (such that $$$a_1 < a_2 < \ldots < a_n$$$), differences between all adjacent (consecutive) elements are equal (i.e. $$$a_2 - a_1 = a_3 - a_2 = \ldots = a_n - a_{n-1})$$$. It can be proven that such an array always exists under the constraints given below.Among all possible arrays that satisfy the given conditions, we ask you to restore one which has the minimum possible maximum element. In other words, you have to minimize $$$\max(a_1, a_2, \dots, a_n)$$$.You have to answer $$$t$$$ independent test cases. | For each test case, print the answer: $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the $$$i$$$-th element of the required array. If there are several answers, you can print any (it also means that the order of elements doesn't matter). It can be proven that such an array always exists under the given constraints. | C | ca9d97e731e86cf8223520f39ef5d945 | 02714c3a4c6f6e1aacfbe82a5c9b8ddb | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"number theory",
"brute force",
"math"
] | 1599230100 | ["5\n2 1 49\n5 20 50\n6 20 50\n5 3 8\n9 13 22"] | null | PASSED | 1,200 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$2 \le n \le 50$$$; $$$1 \le x < y \le 50$$$) — the length of the array and two elements that are present in the array, respectively. | ["1 49 \n20 40 30 50 10\n26 32 20 38 44 50 \n8 23 18 13 3 \n1 10 13 4 19 22 25 16 7"] | #include <stdlib.h>
#include <stdio.h>
#include <math.h>
int main(){
int cases;
scanf("%d", &cases);
for(int i = 0; i < cases; i++){
int length, one, two;
scanf("%d %d %d\n", &length, &one, &two);
int temp = two;
int gap = two - one;
int distance = (int) ceil((double)gap / (length - 1));
while(gap % distance){
distance++;
}
while(two > 0 && length - 1){
printf("%d ", two);
two -= distance;
length--;
}
temp += distance;
while(length - 1){
printf("%d ", temp);
temp += distance;
length--;
}
printf("%d\n", two > 0 ? two : temp);
}
return 0;
} | |
We have a secret array. You don't know this array and you have to restore it. However, you know some facts about this array: The array consists of $$$n$$$ distinct positive (greater than $$$0$$$) integers. The array contains two elements $$$x$$$ and $$$y$$$ (these elements are known for you) such that $$$x < y$$$. If you sort the array in increasing order (such that $$$a_1 < a_2 < \ldots < a_n$$$), differences between all adjacent (consecutive) elements are equal (i.e. $$$a_2 - a_1 = a_3 - a_2 = \ldots = a_n - a_{n-1})$$$. It can be proven that such an array always exists under the constraints given below.Among all possible arrays that satisfy the given conditions, we ask you to restore one which has the minimum possible maximum element. In other words, you have to minimize $$$\max(a_1, a_2, \dots, a_n)$$$.You have to answer $$$t$$$ independent test cases. | For each test case, print the answer: $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the $$$i$$$-th element of the required array. If there are several answers, you can print any (it also means that the order of elements doesn't matter). It can be proven that such an array always exists under the given constraints. | C | ca9d97e731e86cf8223520f39ef5d945 | f2d7577f6316e8fb0cdaab08e1c8ed92 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"number theory",
"brute force",
"math"
] | 1599230100 | ["5\n2 1 49\n5 20 50\n6 20 50\n5 3 8\n9 13 22"] | null | PASSED | 1,200 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$2 \le n \le 50$$$; $$$1 \le x < y \le 50$$$) — the length of the array and two elements that are present in the array, respectively. | ["1 49 \n20 40 30 50 10\n26 32 20 38 44 50 \n8 23 18 13 3 \n1 10 13 4 19 22 25 16 7"] | #include <stdio.h>
int main()
{
int t,i;
scanf("%d",&t);
for(i=0;i<t;i++)
{ int n,x,y,j,k,l,d,o,u;
scanf("%d %d %d",&n,&x,&y);
for(j=n-1;j>0;j--)
{
if((y-x)%j==0)
break;
}
u=y;
d=(y-x)/j;
for(k=0;k<n;k++,y=y-d)
{
if(y>0)
printf("%d ",y);
else break;
}
for(l=k,o=1;l<n;l++,o++)
printf("%d ",u+o*d);
printf("\n");
}
} | |
We have a secret array. You don't know this array and you have to restore it. However, you know some facts about this array: The array consists of $$$n$$$ distinct positive (greater than $$$0$$$) integers. The array contains two elements $$$x$$$ and $$$y$$$ (these elements are known for you) such that $$$x < y$$$. If you sort the array in increasing order (such that $$$a_1 < a_2 < \ldots < a_n$$$), differences between all adjacent (consecutive) elements are equal (i.e. $$$a_2 - a_1 = a_3 - a_2 = \ldots = a_n - a_{n-1})$$$. It can be proven that such an array always exists under the constraints given below.Among all possible arrays that satisfy the given conditions, we ask you to restore one which has the minimum possible maximum element. In other words, you have to minimize $$$\max(a_1, a_2, \dots, a_n)$$$.You have to answer $$$t$$$ independent test cases. | For each test case, print the answer: $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the $$$i$$$-th element of the required array. If there are several answers, you can print any (it also means that the order of elements doesn't matter). It can be proven that such an array always exists under the given constraints. | C | ca9d97e731e86cf8223520f39ef5d945 | b69640332ba43c7349beec1c3a71df01 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"number theory",
"brute force",
"math"
] | 1599230100 | ["5\n2 1 49\n5 20 50\n6 20 50\n5 3 8\n9 13 22"] | null | PASSED | 1,200 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$2 \le n \le 50$$$; $$$1 \le x < y \le 50$$$) — the length of the array and two elements that are present in the array, respectively. | ["1 49 \n20 40 30 50 10\n26 32 20 38 44 50 \n8 23 18 13 3 \n1 10 13 4 19 22 25 16 7"] | #include <stdio.h>
int main(int argc, char *argv[])
{
int tc;
scanf("%d",&tc);
while(tc--){
int n,x,y;
scanf("%d%d%d",&n,&x,&y);
int a[3000]={0},c=0;
int d,i,j,ans,st;
d=y-x;
for(i=1;i<=d;i++){
if(d%i==0){
ans=(d/i)-1;
if(ans>(n-2))
continue;
else break;
}
}
st=y-(n-1)*i;
while(st<=0)st+=i;
st-=i;
for(j=0;j<n;j++)
printf("%d ",st+=i);
printf("\n");
}
} | |
We have a secret array. You don't know this array and you have to restore it. However, you know some facts about this array: The array consists of $$$n$$$ distinct positive (greater than $$$0$$$) integers. The array contains two elements $$$x$$$ and $$$y$$$ (these elements are known for you) such that $$$x < y$$$. If you sort the array in increasing order (such that $$$a_1 < a_2 < \ldots < a_n$$$), differences between all adjacent (consecutive) elements are equal (i.e. $$$a_2 - a_1 = a_3 - a_2 = \ldots = a_n - a_{n-1})$$$. It can be proven that such an array always exists under the constraints given below.Among all possible arrays that satisfy the given conditions, we ask you to restore one which has the minimum possible maximum element. In other words, you have to minimize $$$\max(a_1, a_2, \dots, a_n)$$$.You have to answer $$$t$$$ independent test cases. | For each test case, print the answer: $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the $$$i$$$-th element of the required array. If there are several answers, you can print any (it also means that the order of elements doesn't matter). It can be proven that such an array always exists under the given constraints. | C | ca9d97e731e86cf8223520f39ef5d945 | 025166ec531a08802e98096edb8245ee | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"number theory",
"brute force",
"math"
] | 1599230100 | ["5\n2 1 49\n5 20 50\n6 20 50\n5 3 8\n9 13 22"] | null | PASSED | 1,200 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$2 \le n \le 50$$$; $$$1 \le x < y \le 50$$$) — the length of the array and two elements that are present in the array, respectively. | ["1 49 \n20 40 30 50 10\n26 32 20 38 44 50 \n8 23 18 13 3 \n1 10 13 4 19 22 25 16 7"] | #include<stdio.h>
int main()
{
long long int N,T,U,M,i,j,V,k,x,m,y,n;
scanf("%lld", &T);
for(i=1; i<=T; i++)
{
scanf("%lld %lld %lld", &N, &U, &V);
long long int A[N];
x=V-U;
if(x%(N-1)==0)
{
y=x/(N-1);
for(j=0; j<N; j++)
{
A[j]=U;
U=U+y;
}
}
else
{
for(j=(N-2); j>=1; j--)
{
if(x%j==0)
{
k=j;
break;
}
}
y=x/k;
m=N-k-1;
M=U;
n=-1;
for(j=m; j>=0; j--)
{
A[j]=M;
if(A[j]<=0)
{
n=j;
break;
}
M=M-y;
}
if(n==-1)
{
M=U+y;
for(j=m+1; j<N; j++)
{
A[j]=M;
M=M+y;
}
}
else
{
m=m-j-1;
M=U;
for(j=m; j>=0; j--)
{
A[j]=M;
M=M-y;
}
M=U+y;
for(j=m+1; j<N; j++)
{
A[j]=M;
M=M+y;
}
}
}
for(j=0; j<N; j++)
{
printf("%lld ", A[j]);
}
printf("\n");
}
return 0;
} | |
We have a secret array. You don't know this array and you have to restore it. However, you know some facts about this array: The array consists of $$$n$$$ distinct positive (greater than $$$0$$$) integers. The array contains two elements $$$x$$$ and $$$y$$$ (these elements are known for you) such that $$$x < y$$$. If you sort the array in increasing order (such that $$$a_1 < a_2 < \ldots < a_n$$$), differences between all adjacent (consecutive) elements are equal (i.e. $$$a_2 - a_1 = a_3 - a_2 = \ldots = a_n - a_{n-1})$$$. It can be proven that such an array always exists under the constraints given below.Among all possible arrays that satisfy the given conditions, we ask you to restore one which has the minimum possible maximum element. In other words, you have to minimize $$$\max(a_1, a_2, \dots, a_n)$$$.You have to answer $$$t$$$ independent test cases. | For each test case, print the answer: $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the $$$i$$$-th element of the required array. If there are several answers, you can print any (it also means that the order of elements doesn't matter). It can be proven that such an array always exists under the given constraints. | C | ca9d97e731e86cf8223520f39ef5d945 | 6bac318f610837adedf971341990f047 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"number theory",
"brute force",
"math"
] | 1599230100 | ["5\n2 1 49\n5 20 50\n6 20 50\n5 3 8\n9 13 22"] | null | PASSED | 1,200 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$2 \le n \le 50$$$; $$$1 \le x < y \le 50$$$) — the length of the array and two elements that are present in the array, respectively. | ["1 49 \n20 40 30 50 10\n26 32 20 38 44 50 \n8 23 18 13 3 \n1 10 13 4 19 22 25 16 7"] | #pragma region kyopuro_templates
#pragma GCC optimize("Ofast")
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<stdbool.h>
#include<assert.h>
#include<time.h>
#include<ctype.h>
typedef long long ll;
typedef long double ld;
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define rrep(i,l,r)for(ll i=(l);i>=(r);i--)
#define INF (1LL<<62)
#define MOD1 1000000007
#define MOD2 998244353
#define MAX_N (1 << 20)
#define YES printf("Yes\n")
#define NO printf("No\n")
#define PN printf("\n")
#define charsize 100005 //10^5+5
#define PI 3.141592653589793238
void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a= c;}
void cin(ll *n){ scanf("%lld",&(*n)); }
ll max2(ll a,ll b){return a>=b?a:b;}
ll min2(ll a,ll b){return a>=b?b:a;}
ll min3(ll a, ll b, ll c){return (a<=b && a<=c) ? a : b<=c ? b : c;}
ll max3(ll a, ll b, ll c){return (a>=b && a>=c) ? a : b>=c ? b : c;}
ll minn(ll n, ll a[]){ll b=INF;rep(i,0,n) b=min2(b,a[i]);return b;}
ll maxn(ll n, ll a[]){ll b=-INF;rep(i,0,n) b=max2(b,a[i]);return b;}
ll POW(ll a, ll b){ll c=1;rep(i,0,b) c*=a;return c;}
double POW_d(double a, double b){double c=1;rep(i,0,b) c*=a;return c;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll mod_MOD1(ll n){n+= n<0?((-n)/MOD1+1)*MOD1:0; return n%=MOD1;}
ll mod_p(ll n ,ll p){n+= n<0?((-n)/p+1)*p:0; return n%=p;}
ll change_into_num(char s[] , ll len, ll p){ return !p ? 0 : POW(10,p-1)*(s[len-p]-'0') + change_into_num(s,len,p-1); }
ll digits(ll a, ll b){return a/b?1+digits(a/b,b):1;}
ll base(ll n, ll a, ll i){return i==1?n%a:base(n/a,a,i-1);}
ll is_inArr1(ll x, ll n){ return ( x<0 || x>=n ) ? 0 : 1 ; }
ll is_inArr2(ll y, ll x, ll h, ll w){ return ( y<0 || y>=h || x<0 || x>=w ) ? 0 : 1 ; }
void lr_lower( int *l, int *r, ll am, ll val , int type ){ (type<3) ? ( am < val ? ( *l = (*l+*r)/2 ) : ( *r= (*l+*r)/2 ) ) : ( am <= val ? ( *l = (*l+*r)/2 ) : ( *r= (*l+*r)/2 ) ); }
void lr_upper( int *l, int *r, ll am, ll val , int type ){ (type<3) ? ( am <= val ? ( *l = (*l+*r)/2 ) : ( *r= (*l+*r)/2 ) ) : ( am < val ? ( *l = (*l+*r)/2 ) : ( *r= (*l+*r)/2 ) ); }
int cmp_lower( ll a, ll b, int type ){ return (type==1) ? ( a==b ? 1 : 0 ) : (type==2) ? ( a>=b ? 1 : 0 ) : ( a>b ? 1 : 0 ) ; }
int cmp_upper( ll a, ll b, int type ){ return (type==1) ? ( a==b ? 1 : 0 ) : (type==2) ? ( a<=b ? 1 : 0 ) : ( a<b ? 1 : 0 ) ; }
// return smallest p which meets a[p]==val :1 >=:2 >:3
ll lower_bound( ll a[], int l, int r, ll val , int type ){ while(r-l>1) lr_lower(&l,&r,a[ (l+r)/2 ],val,type); return cmp_lower(a[l],val,type) ? l : cmp_lower(a[r],val,type) ? r : -1; }
// return biggest p which meets a[p]==val :1 <=:2 <:3
ll upper_bound( ll a[], int l, int r, ll val , int type ){ while(r-l>1) lr_upper(&l,&r,a[ (l+r)/2 ],val,type); return cmp_upper(a[r],val,type) ? r : cmp_upper(a[l],val,type) ? l : -1; }
// count i which meets ai==x
ll count(ll a[], int l, int r, ll x){ int p = lower_bound(a,l,r,x,1); return p==-1 ? 0 : upper_bound(a,p,r,x,1)-p+1; }
ll *factors[2] , fac_cnt=0 , is_factor_prepared=0;
ll factor_pre(){ rep(i,0,1){ if(is_factor_prepared++) return 0; } ll tmp=(1e6)/2+1, fac_tmp[tmp]; rep(i,0,tmp){fac_tmp[i]=i?2*i+1:2;} rep(i,1,tmp){if(fac_tmp[i]){ repp(j,3,tmp/(2*i+1)+1,2 ){ if( j*(2*i+1)<tmp ) fac_tmp[ (j*(2*i+1)-1)/2 ]=0; } }else continue;} rep(i,0,tmp){if(fac_tmp[i]){ rep(j,0,2){ factors[j] = realloc( factors[j] , sizeof(ll)*( fac_cnt +1 ) ); factors[j][j?fac_cnt++:fac_cnt]=j?0:fac_tmp[i]; } } } return 0; }
ll factor(ll n, ll new_common_plus){ factor_pre(); rep(i,0,fac_cnt){ ll cnt=0; rep(j,0,1){ while( ( cnt+= n %factors[0][i]==0 ? 1 : 0 ) && (n/=factors[0][i]) %factors[0][i]==0 ) continue; } factors[1][i]= new_common_plus==1 ? cnt : new_common_plus==2 ? max2(factors[1][i],cnt) : factors[1][i]+cnt ; if( factors[0][i]> n ) break; } return n; }
ll judge_prime(ll n){ factor_pre(); rep(i,0,fac_cnt){ if(n<factors[0][i]*factors[0][i] || n==factors[0][i]) break; else if(n%factors[0][i]==0) n/=n; } return n==1?0:1; }
ll *mf_arr,*inv_arr,*finv_arr,is_minv_made=0,is_mf_made=0,num_of_inv=2*1e6+10;
ll makeinv(ll n , ll mod){ rep(i,0,1){if(is_minv_made++) return 0;} inv_arr = realloc(inv_arr, sizeof(ll)*2 ); finv_arr = realloc(finv_arr, sizeof(ll)*2 ); inv_arr[1]=1;finv_arr[0]=finv_arr[1]=1; rep(i,2,n+1){ inv_arr = realloc(inv_arr, sizeof(ll)*(i+1) ); finv_arr = realloc(finv_arr, sizeof(ll)*(i+1) ); inv_arr[i]= mod - inv_arr[mod%i] * (mod / i) % mod; finv_arr[i] = finv_arr[i - 1] * inv_arr[i] % mod; } return 0; }
ll make_mf(ll n, ll mod){ rep(i,0,1){ if(is_mf_made++) return 0; } mf_arr = realloc(mf_arr, sizeof(ll)*2 ); ll x=1; mf_arr[0]=mf_arr[1]=x; rep(i,2,n+1){ x=x*i%mod; mf_arr = realloc(mf_arr, sizeof(ll)*(i+1) ); mf_arr[i]=x; } return 0; }
ll m_inv(ll x, ll mod, ll is_fac ){ makeinv(num_of_inv,mod); return is_fac?finv_arr[x]:inv_arr[x]; }
ll m_f(ll x, ll mod){ make_mf(num_of_inv,mod); return mf_arr[x]; }
ll mod_nck(ll n, ll k, ll mod){ return m_f(n,mod)*m_inv(k,mod,1)%mod*m_inv(n-k,mod,1)%mod; }
ll m_p(ll r,ll n,ll mod){ ll t=1,s=r; while(n>0){ t = (n&1) ? t*s%mod : t; s=s*s%mod; n>>=1; } return r?t:0; }
ll m_mul2(ll a, ll b, ll mod){ return a*b%mod; }
ll m_mul3(ll a, ll b, ll c, ll mod){ return m_mul2(a*b%mod,c,mod); }
ll m_mul4(ll a, ll b, ll c, ll d, ll mod){ return m_mul3(a*b%mod,c,d,mod); }
ll m_mul5(ll a, ll b, ll c, ll d, ll e, ll mod){ return m_mul4(a*b%mod,c,d,e,mod); }
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
int cmp_string( const void * a , const void * b ) { return strcmp( (char *)a , (char *)b ); } // qsort((void*)s,n,sizeof(s[0]),int_sort );
int cmp_char(const void * a, const void * b) { return *(char *)a - *(char *)b;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
void sort_string(int n,int size,char s[][size]){ qsort( (void*)s , n , sizeof(s[0]) , cmp_string ); }
void sort_char(char *s){ qsort( (void *)s , strlen(s) , sizeof(char) , cmp_char ); }
ll unique_string(ll n ,ll size, char s[][size]){ ll ans=1; rep(i,1,n) if( strcmp(s[i],s[i-1]) ) ans++; return ans; }
ll unique_num(ll n , ll a[]){ ll ans=1; rep(i,1,n) if( a[i]!=a[i-1] ) ans++; return ans; }
ll compare(ll a, ll b){ return a<b?-1:a>b?1:0; }
typedef struct{ ll a , b;}fr;
int cmp1( const void *p, const void *q ){
ll pa=((fr*)p)->a; ll qa=((fr*)q)->a; return compare(pa,qa);
}
int cmp2( const void *p, const void *q ){
ll pa=((fr*)p)->a; ll qa=((fr*)q)->a; return compare(qa,pa);
}
void strsortup(fr*a,int n){qsort(a,n,sizeof(fr),cmp1);}
void strsortdown(fr*a,int n){qsort(a,n,sizeof(fr),cmp2);}
void sort_partial(ll a[],int begin,int end,int is_increase){
ll *b; b = (ll *) malloc( sizeof(ll)*(end-begin) );
rep(i,begin,end) b[i-begin]=a[i];
if(is_increase) sortup(b,end-begin); else sortdown(b,end-begin);
rep(i,begin,end) a[i]=b[i-begin];
}
#pragma region AVL
/*---------------------------AVL start--------------------------------*/
//https://qiita.com/mikecat_mixc/items/e9f8248de2ae7f7a0a29
typedef struct node_AVL_set{
ll val;
int diff;
int cnt;
struct node_AVL_set *child[2];
}AVL_set;
void AVL_set_inside_rotate(AVL_set **node, int is_right){
int l = is_right==false , r = is_right==true , sign = is_right ? 1 : -1;
if((*node)->child[l] != NULL){
AVL_set* left = (*node)->child[l];
int a= (*node)->diff * sign , b= left->diff * sign ,na,nb;
if(b+1){
na=a-1-b;
nb= (a-b) ? b-1 : a-2;
}else{
na=a-1;
nb= a ? b-1 : a+b-2;
}
(*node)->diff = na * sign;
left->diff = nb * sign;
/* rotate-> */
(*node)->child[l] = (*node)->child[l]->child[r];
left->child[r] = *node;
*node = left;
}
}
int AVL_set_inside_update(AVL_set **node, ll data, int add){
if(*node == NULL){
if(add==2){
*node = malloc(sizeof(AVL_set));
(*node)->val = data;
(*node)->cnt = 1;
(*node)->diff = 0;
(*node)->child[0] = NULL;
(*node)->child[1] = NULL;
}
return add==2 ? *node != NULL : 0;
}else{
int l, delta, delta_sign; AVL_set *next_node;
if(data == (*node)->val){
if(add==2){
(*node)->cnt++;
return 0;
}else{
if( add && (*node)->cnt > 1 ){
(*node)->cnt--; return 0;
}else{
if((*node)->child[1] == NULL){
next_node = (*node)->child[0];
free(*node);
*node = next_node;
return -1;
}else if((*node)->child[0] == NULL){
next_node = (*node)->child[1];
free(*node);
*node = next_node;
return -1;
}else{
for(next_node = (*node)->child[0];
next_node->child[1] != NULL;
next_node = next_node->child[1]);
(*node)->val = next_node->val;
l=0;
delta_sign=1;
delta = AVL_set_inside_update(&(*node)->child[l], next_node->val, add);
}
}
}
}else{
l = data >= (*node)->val ? 1 : 0;
delta_sign = data < (*node)->val ? 1 : -1;
delta = AVL_set_inside_update(&(*node)->child[l], data, add);
}
if( delta ){
int orig_diff = (*node)->diff;
int do_rotate = 0, rotate_l , diff_sign , rotate_right;
(*node)->diff += delta * delta_sign;
if((*node)->diff > 1){
do_rotate = 1;
rotate_l = 0;
diff_sign = 1;
rotate_right = 1;
}else if((*node)->diff < -1){
do_rotate = 1;
rotate_l = 1;
diff_sign = -1;
rotate_right = 0;
}
if(do_rotate){
int child_diff = (*node)->child[rotate_l]->diff;
if((*node)->child[rotate_l]->diff * diff_sign < 0){
AVL_set_inside_rotate(&(*node)->child[rotate_l], !rotate_right);
}
AVL_set_inside_rotate(node, rotate_right);
return delta < 0 && child_diff != 0 ? -1 : 0;
}
if (delta > 0 && orig_diff == 0) return 1;
else if(delta < 0 && orig_diff != 0) return -1;
else return 0;
}else{
return 0;
}
}
}
void AVL_set_inside_print(const AVL_set *node, int depth){
if(node == NULL) return;
AVL_set_inside_print(node->child[1], depth + 1);
printf("%lld %d\n", node->val,node->cnt);
AVL_set_inside_print(node->child[0], depth + 1);
}
void AVL_set_inside_free(AVL_set *node){
if(node == NULL) return;
AVL_set_inside_free(node->child[0]);
AVL_set_inside_free(node->child[1]);
free(node);
}
ll AVL_set_inside_count(AVL_set *root, ll val){
AVL_set *node; node = root;
while(node){
if (val < node->val) node = node->child[0];
else if(val > node->val) node = node->child[1];
else return node->cnt;
}
return 0;
}
ll AVL_set_inside_minmax(AVL_set *root, int type){
while(root->child[type] !=NULL) root= root->child[type];
return root->val;
}
void AVL_set_inside_swap(AVL_set **node1, AVL_set **node2){
AVL_set *tmp; tmp=*node1; *node1=*node2; *node2=tmp;
}
#define set_MAX_SIZE 514511
ll set_main( int command , int set_num , ll val ){
static bool set_is_init=false;
static AVL_set *set_pointer[set_MAX_SIZE];
static ll set_siz[set_MAX_SIZE];
if(!set_is_init){ set_is_init=true; rep(i,0,set_MAX_SIZE){ *(set_pointer+i) = NULL; set_siz[i]=0; } }
if(command==-1){ AVL_set_inside_print( set_pointer[set_num] ,0); }
if(command==1){ AVL_set_inside_count(set_pointer[set_num],val) ? 1 : set_siz[set_num]++; AVL_set_inside_update( &set_pointer[set_num] , val , 2 ); }
if(command==2){ return AVL_set_inside_count(set_pointer[set_num],val); }
if(command==3){ ( AVL_set_inside_count(set_pointer[set_num],val) > 1 ) ? 1 : set_siz[set_num]--; AVL_set_inside_update( &set_pointer[set_num] , val,1); }
if(command==4){ set_siz[set_num]--; AVL_set_inside_update( &set_pointer[set_num] , val , 0 ); }
if(command==5){ set_siz[set_num]=0; AVL_set_inside_free( set_pointer[set_num] ); set_pointer[set_num] = NULL; }
if(command==6){ return set_siz[set_num]; }
if(command==7){ return AVL_set_inside_minmax(set_pointer[set_num],1); }
if(command==8){ return AVL_set_inside_minmax(set_pointer[set_num],0); }
if(command==9){ AVL_set_inside_swap(&set_pointer[set_num],&set_pointer[val]); }
return 0;
}
void set_print(int set_num){ set_main(-1,set_num,0); }
void set_insert(int set_num, ll val){ set_main(1,set_num,val); }
ll set_count(int set_num, ll val){ return set_main(2,set_num,val); }
void set_erase(int set_num, ll val, int is_all){ if(is_all) set_main(4,set_num,val); else set_main(3,set_num,val); }
void set_clear(int set_num){ set_main(5,set_num,0); }
ll set_size(int set_num){ return set_main(6,set_num,0); }
ll set_max(int set_num){ return set_main(7,set_num,0); }
ll set_min(int set_num){ return set_main(8,set_num,0); }
void set_swap(ll set_num1, ll set_num2){ set_main(9,set_num1,set_num2); }
/*
insert *
size *
clear *
erase *
count *
max *
min *
swap *
begin
end
merge source の要素のキーと等価なキーの要素がある場合、その要素は source から抽出されない
lower_bound
upper_bound
*/
// ll map_main()
/*---------------------------AVL start--------------------------------*/
#pragma endregion AVL
#pragma endregion kyopuro_templates
char s[1151154];
void solve(){
// fgets(s,sizeof(s),stdin);
ll n,x,y;
ll ans=0;
cin(&n);
cin(&x);
cin(&y);
// scanf("%s",s);
ll d=y-x;
if(!d){
rep(i,0,n){
printf("%lld ",x);
}PN;
return;
}
rrep(i,n-1,1){
if(d%i==0){
ll gap=d/i;
ll a[n];
a[n-1]=y;
// printf("%lld")
rrep(j,n-2,0){
a[j]=a[j+1]-gap;
}
ll plus=0;
if(a[0]<1){
plus=(1-a[0])/gap;
if((1-a[0])%gap){
plus++;
}
}
rep(j,0,n){
printf("%lld ",a[j]+plus*gap);
}PN;
return;
}
}
printf("-1\n");
// printf("%lld\n");
}
int main(void){
ll T=1;
cin(&T);
rep(i,0,T){ solve(); }
return 0;
}
/*
while (ng + 1 < ok) {
ll p = ng + (ok - ng) / 2;
ll cnt = 0;
rep(i,0,n){
cnt += (a[i] + p - 1) / p - 1;
}
if (cnt <= k) ok = p; else ng = p;
}
*/
// 10^18 2^60 3^38 5^26
| |
We have a secret array. You don't know this array and you have to restore it. However, you know some facts about this array: The array consists of $$$n$$$ distinct positive (greater than $$$0$$$) integers. The array contains two elements $$$x$$$ and $$$y$$$ (these elements are known for you) such that $$$x < y$$$. If you sort the array in increasing order (such that $$$a_1 < a_2 < \ldots < a_n$$$), differences between all adjacent (consecutive) elements are equal (i.e. $$$a_2 - a_1 = a_3 - a_2 = \ldots = a_n - a_{n-1})$$$. It can be proven that such an array always exists under the constraints given below.Among all possible arrays that satisfy the given conditions, we ask you to restore one which has the minimum possible maximum element. In other words, you have to minimize $$$\max(a_1, a_2, \dots, a_n)$$$.You have to answer $$$t$$$ independent test cases. | For each test case, print the answer: $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the $$$i$$$-th element of the required array. If there are several answers, you can print any (it also means that the order of elements doesn't matter). It can be proven that such an array always exists under the given constraints. | C | ca9d97e731e86cf8223520f39ef5d945 | 23737a71305ea57d6ecdc82e2c41cafb | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"number theory",
"brute force",
"math"
] | 1599230100 | ["5\n2 1 49\n5 20 50\n6 20 50\n5 3 8\n9 13 22"] | null | PASSED | 1,200 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$2 \le n \le 50$$$; $$$1 \le x < y \le 50$$$) — the length of the array and two elements that are present in the array, respectively. | ["1 49 \n20 40 30 50 10\n26 32 20 38 44 50 \n8 23 18 13 3 \n1 10 13 4 19 22 25 16 7"] | #include<stdio.h>
int main()
{
long long int N,T,U,M,i,j,V,k,x,m,y,n;
scanf("%lld", &T);
for(i=1; i<=T; i++)
{
scanf("%lld %lld %lld", &N, &U, &V);
long long int A[N];
x=V-U;
if(x%(N-1)==0)
{
y=x/(N-1);
for(j=0; j<N; j++)
{
A[j]=U;
U=U+y;
}
}
else
{
for(j=(N-2); j>=1; j--)
{
if(x%j==0)
{
k=j;
break;
}
}
y=x/k;
m=N-k-1;
M=U;
n=-1;
for(j=m; j>=0; j--)
{
A[j]=M;
if(A[j]<=0)
{
n=j;
break;
}
M=M-y;
}
if(n==-1)
{
M=U+y;
for(j=m+1; j<N; j++)
{
A[j]=M;
M=M+y;
}
}
else
{
m=m-j-1;
M=U;
for(j=m; j>=0; j--)
{
A[j]=M;
M=M-y;
}
M=U+y;
for(j=m+1; j<N; j++)
{
A[j]=M;
M=M+y;
}
}
}
for(j=0; j<N; j++)
{
printf("%lld ", A[j]);
}
printf("\n");
}
return 0;
} | |
We have a secret array. You don't know this array and you have to restore it. However, you know some facts about this array: The array consists of $$$n$$$ distinct positive (greater than $$$0$$$) integers. The array contains two elements $$$x$$$ and $$$y$$$ (these elements are known for you) such that $$$x < y$$$. If you sort the array in increasing order (such that $$$a_1 < a_2 < \ldots < a_n$$$), differences between all adjacent (consecutive) elements are equal (i.e. $$$a_2 - a_1 = a_3 - a_2 = \ldots = a_n - a_{n-1})$$$. It can be proven that such an array always exists under the constraints given below.Among all possible arrays that satisfy the given conditions, we ask you to restore one which has the minimum possible maximum element. In other words, you have to minimize $$$\max(a_1, a_2, \dots, a_n)$$$.You have to answer $$$t$$$ independent test cases. | For each test case, print the answer: $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the $$$i$$$-th element of the required array. If there are several answers, you can print any (it also means that the order of elements doesn't matter). It can be proven that such an array always exists under the given constraints. | C | ca9d97e731e86cf8223520f39ef5d945 | bd03bb760887e6d041b51f8f66ec69b7 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"number theory",
"brute force",
"math"
] | 1599230100 | ["5\n2 1 49\n5 20 50\n6 20 50\n5 3 8\n9 13 22"] | null | PASSED | 1,200 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$2 \le n \le 50$$$; $$$1 \le x < y \le 50$$$) — the length of the array and two elements that are present in the array, respectively. | ["1 49 \n20 40 30 50 10\n26 32 20 38 44 50 \n8 23 18 13 3 \n1 10 13 4 19 22 25 16 7"] | //set many funcs template
//Ver.20190820
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<time.h>
#include<assert.h>
#define inf 1072114514
#define llinf 4154118101919364364
#define mod 1000000007
#define pi 3.1415926535897932384
int max(int a,int b){if(a>b){return a;}return b;}
int min(int a,int b){if(a<b){return a;}return b;}
int zt(int a,int b){return max(a,b)-min(a,b);}
int round(int a,int b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
int ceil(int a,int b){if(a%b==0){return a/b;}return (a/b)+1;}
int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;}
int nCr(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
int nHr(int a,int b){return nCr(a+b-1,b);}
int fact(int a){int i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
int pow(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
int dsum(int x){int r=0;while(x){r+=(x%10);x/=10;}return r;}
int dsumb(int x,int b){int r=0;while(x){r+=(x%b);x/=b;}return r;}
int sankaku(int x){return ((1+x)*x)/2;}
void swap(int *a,int *b){int c;c=(*a);(*a)=(*b);(*b)=c;}
long long llmax(long long a,long long b){if(a>b){return a;}return b;}
long long llmin(long long a,long long b){if(a<b){return a;}return b;}
long long llzt(long long a,long long b){return llmax(a,b)-llmin(a,b);}
long long llround(long long a,long long b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
long long llceil(long long a,long long b){if(a%b==0){return a/b;}return (a/b)+1;}
long long llgcd(long long a,long long b){long long c;while(b!=0){c=a%b;a=b;b=c;}return a;}
long long lllcm(long long a,long long b){long long c=llgcd(a,b);a/=c;return a*b;}
long long llnCr(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
long long llnHr(long long a,long long b){return llnCr(a+b-1,b);}
long long llfact(long long a){long long i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
long long llpow(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
long long lldsum(long long x){long long r=0;while(x){r+=(x%10);x/=10;}return r;}
long long lldsumb(long long x,long long b){long long r=0;while(x){r+=(x%b);x/=b;}return r;}
long long llsankaku(long long x){return ((1+x)*x)/2;}
void llswap(long long *a,long long *b){long long c;c=(*a);(*a)=(*b);(*b)=c;}
double dbmax(double a,double b){if(a>b){return a;}return b;}
double dbmin(double a,double b){if(a<b){return a;}return b;}
double dbzt(double a,double b){return dbmax(a,b)-dbmin(a,b);}
void dbswap(double *a,double *b){double c;c=(*a);(*a)=(*b);(*b)=c;}
void chswap(char *a,char *b){char c;c=(*a);(*a)=(*b);(*b)=c;}
int sortfncsj(const void *a,const void *b){if(*(int *)a>*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int sortfnckj(const void *a,const void *b){if(*(int *)a<*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int llsortfncsj(const void *a,const void *b){if(*(long long *)a>*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int llsortfnckj(const void *a,const void *b){if(*(long long *)a<*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int dbsortfncsj(const void *a,const void *b){if(*(double *)a>*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}
int dbsortfnckj(const void *a,const void *b){if(*(double *)a<*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}
int strsortfncsj(const void *a,const void *b){return strcmp((char *)a,(char *)b);}
int strsortfnckj(const void *a,const void *b){return strcmp((char *)b,(char *)a);}
int chsortfncsj(const void *a,const void *b){if(*(char *)a>*(char *)b){return 1;}if(*(char *)a==*(char *)b){return 0;}return -1;}
int chsortfnckj(const void *a,const void *b){if(*(char *)a<*(char *)b){return 1;}if(*(char *)a==*(char *)b){return 0;}return -1;}
void shuffledget(int x[],int n){
int i,b[524288],p,c;
for(i=0;i<n;i++){
b[i]=i;
}
for(i=n;i>=1;i--){
p=rand()%i;
c=b[i-1];b[i-1]=b[p];b[p]=c;
}
for(i=0;i<n;i++){
scanf("%d",&x[b[i]]);
}
}
int dx4[4]={1,-1,0,0};
int dy4[4]={0,0,1,-1};
int dx8[8]={-1,-1,-1,0,0,1,1,1};
int dy8[8]={-1,0,1,-1,1,-1,0,1};
int search(int x,int a[],int n){
int st=0,fi=n-1,te;
while(st<=fi){
te=(st+fi)/2;
if(a[te]<x){st=te+1;}else{fi=te-1;}
}
return st;
}
void prarr(int arr[],int n){
int i;
for(i=0;i<n;i++){
if(i){printf(" ");}
printf("%d",arr[i]);
}
printf("\n");
return;
}
void getperm(int a[],int n){
int i,p;
for(i=0;i<n;i++){
a[i]=i;
}
for(i=n-1;i>=1;i--){
p=rand()%(i+1);
swap(&a[p],&a[i]);
}
}
typedef struct{
int val;
int node;
}sd;
int sdsortfnc(const void *a,const void *b){
if(((sd*)a)->val < ((sd*)b)->val){return -1;}
if(((sd*)a)->val > ((sd*)b)->val){return 1;}
return 0;
}
void coordinate_comp(int a[],int n){
int i,c=0;
sd dat[524288];
for(i=0;i<n;i++){
dat[i].val=a[i];
dat[i].node=i;
}
qsort(dat,n,sizeof(dat[0]),sdsortfnc);
a[dat[0].node]=c;
for(i=1;i<n;i++){
if(dat[i-1].val!=dat[i].val){c++;}
a[dat[i].node]=c;
}
}
long long f(long long a,long long b,long long x,long long y,long long n){
long long c=llmin(a-x,n);
a-=c;n-=c;
c=llmin(b-y,n);
b-=c;n-=c;
return a*b;
}
int main(void){
int t;
scanf("%d",&t);
while(t>0){
t--;
long long n,x,y,d;
scanf("%lld%lld%lld",&n,&x,&y);
d=y-x;
long long rd=-1,rmx=llinf;
for(int i=1;i<=d;i++){
if((d%i)!=0){continue;}
if(((d/i)+1)>n){continue;}
long long cmx,fc;
fc=(y%i);if(fc==0){fc=i;}
cmx=llmax(y,fc+(n-1)*i);
if(cmx<rmx){
rmx=cmx;
rd=i;
}
}
for(int i=0;i<n;i++){
if(i){printf(" ");}
printf("%lld",rmx);
rmx-=rd;
}puts("");
}
return 0;
}
| |
We have a secret array. You don't know this array and you have to restore it. However, you know some facts about this array: The array consists of $$$n$$$ distinct positive (greater than $$$0$$$) integers. The array contains two elements $$$x$$$ and $$$y$$$ (these elements are known for you) such that $$$x < y$$$. If you sort the array in increasing order (such that $$$a_1 < a_2 < \ldots < a_n$$$), differences between all adjacent (consecutive) elements are equal (i.e. $$$a_2 - a_1 = a_3 - a_2 = \ldots = a_n - a_{n-1})$$$. It can be proven that such an array always exists under the constraints given below.Among all possible arrays that satisfy the given conditions, we ask you to restore one which has the minimum possible maximum element. In other words, you have to minimize $$$\max(a_1, a_2, \dots, a_n)$$$.You have to answer $$$t$$$ independent test cases. | For each test case, print the answer: $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the $$$i$$$-th element of the required array. If there are several answers, you can print any (it also means that the order of elements doesn't matter). It can be proven that such an array always exists under the given constraints. | C | ca9d97e731e86cf8223520f39ef5d945 | bec9e5330baaa3a2388394fab30f7f6a | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"number theory",
"brute force",
"math"
] | 1599230100 | ["5\n2 1 49\n5 20 50\n6 20 50\n5 3 8\n9 13 22"] | null | PASSED | 1,200 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$2 \le n \le 50$$$; $$$1 \le x < y \le 50$$$) — the length of the array and two elements that are present in the array, respectively. | ["1 49 \n20 40 30 50 10\n26 32 20 38 44 50 \n8 23 18 13 3 \n1 10 13 4 19 22 25 16 7"] | #include<stdio.h>
int t,n,x,y,ar[55];
int main()
{
scanf("%d",&t);
while(t--)
{
int m=0,d;
scanf("%d%d%d",&n,&x,&y);
m=n;
if(n==2)
printf("%d %d\n",x,y);
else
{
int i;
for( i=m-1;i>=2;i--)
if((y-x)%i==0)
{
d=(y-x)/i;
break;
}
if(i<2)
d=y-x;//等差数列公差
int k=y/d;
if(k>n-1) k=n-1;
int a1=y-k*d;
if(!a1) a1=d;
//else a1=
for(int i=0;i<n;i++)
printf("%d ",a1+i*d);
printf("\n");
}
}
} | |
We have a secret array. You don't know this array and you have to restore it. However, you know some facts about this array: The array consists of $$$n$$$ distinct positive (greater than $$$0$$$) integers. The array contains two elements $$$x$$$ and $$$y$$$ (these elements are known for you) such that $$$x < y$$$. If you sort the array in increasing order (such that $$$a_1 < a_2 < \ldots < a_n$$$), differences between all adjacent (consecutive) elements are equal (i.e. $$$a_2 - a_1 = a_3 - a_2 = \ldots = a_n - a_{n-1})$$$. It can be proven that such an array always exists under the constraints given below.Among all possible arrays that satisfy the given conditions, we ask you to restore one which has the minimum possible maximum element. In other words, you have to minimize $$$\max(a_1, a_2, \dots, a_n)$$$.You have to answer $$$t$$$ independent test cases. | For each test case, print the answer: $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the $$$i$$$-th element of the required array. If there are several answers, you can print any (it also means that the order of elements doesn't matter). It can be proven that such an array always exists under the given constraints. | C | ca9d97e731e86cf8223520f39ef5d945 | 993dfd60ad3a966eeb055af4aa76ac46 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"number theory",
"brute force",
"math"
] | 1599230100 | ["5\n2 1 49\n5 20 50\n6 20 50\n5 3 8\n9 13 22"] | null | PASSED | 1,200 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$2 \le n \le 50$$$; $$$1 \le x < y \le 50$$$) — the length of the array and two elements that are present in the array, respectively. | ["1 49 \n20 40 30 50 10\n26 32 20 38 44 50 \n8 23 18 13 3 \n1 10 13 4 19 22 25 16 7"] | /******************************************************************************
Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.
*******************************************************************************/
#include <stdio.h>
typedef long long lol;
lol min(lol a,lol b)
{
return a>b?2:1;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
lol n,x,y;
scanf("%lld%lld%lld",&n,&x,&y);
lol i,j,k=y-x,d,m;
if(n==2)
{
printf("%lld %lld\n",x,y);
continue;
}
if((n-1)>=(y-x))
{
if((n-1)==(y-x))
{
for(i=x;i<=y;i++)
printf("%lld ",i);
}
else
{
k=y>n?y:n;
for(i=k-n+1;i<=k;i++)
printf("%lld ",i);
}
printf("\n");
continue;
}
m=(y-x)/(n-1);
if((y-x)%(n-1)!=0) m+=1;
while((y-x)%m!=0) m+=1;
if((y/m)<n)
{
if(y%m!=0)
{
k=((n-1)*m)+(y%m);
i=y%m;
}
else
{
k=((n)*m);
i=m;
}
}
else
{
k=y;
i=y-((n-1)*m);
}
for(;i<=k;i+=m)
printf("%lld ",i);
printf("\n");
}
return 0;
}
| |
We have a secret array. You don't know this array and you have to restore it. However, you know some facts about this array: The array consists of $$$n$$$ distinct positive (greater than $$$0$$$) integers. The array contains two elements $$$x$$$ and $$$y$$$ (these elements are known for you) such that $$$x < y$$$. If you sort the array in increasing order (such that $$$a_1 < a_2 < \ldots < a_n$$$), differences between all adjacent (consecutive) elements are equal (i.e. $$$a_2 - a_1 = a_3 - a_2 = \ldots = a_n - a_{n-1})$$$. It can be proven that such an array always exists under the constraints given below.Among all possible arrays that satisfy the given conditions, we ask you to restore one which has the minimum possible maximum element. In other words, you have to minimize $$$\max(a_1, a_2, \dots, a_n)$$$.You have to answer $$$t$$$ independent test cases. | For each test case, print the answer: $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the $$$i$$$-th element of the required array. If there are several answers, you can print any (it also means that the order of elements doesn't matter). It can be proven that such an array always exists under the given constraints. | C | ca9d97e731e86cf8223520f39ef5d945 | b086f811845d4fb3a4be34ce0bf124c2 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"number theory",
"brute force",
"math"
] | 1599230100 | ["5\n2 1 49\n5 20 50\n6 20 50\n5 3 8\n9 13 22"] | null | PASSED | 1,200 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$2 \le n \le 50$$$; $$$1 \le x < y \le 50$$$) — the length of the array and two elements that are present in the array, respectively. | ["1 49 \n20 40 30 50 10\n26 32 20 38 44 50 \n8 23 18 13 3 \n1 10 13 4 19 22 25 16 7"] | j;main(n,x,y,d,i){for(scanf("%*d");~scanf("%d%d%d",&n,&x,&y);j=0){d=y-x;
for(i=d/n;d%++i;);x%=i;x=x?x:i;y-=n*i-i;for(;j<n;j++)printf("%d ",(x>y?x:y)+i*j);}} | |
We have a secret array. You don't know this array and you have to restore it. However, you know some facts about this array: The array consists of $$$n$$$ distinct positive (greater than $$$0$$$) integers. The array contains two elements $$$x$$$ and $$$y$$$ (these elements are known for you) such that $$$x < y$$$. If you sort the array in increasing order (such that $$$a_1 < a_2 < \ldots < a_n$$$), differences between all adjacent (consecutive) elements are equal (i.e. $$$a_2 - a_1 = a_3 - a_2 = \ldots = a_n - a_{n-1})$$$. It can be proven that such an array always exists under the constraints given below.Among all possible arrays that satisfy the given conditions, we ask you to restore one which has the minimum possible maximum element. In other words, you have to minimize $$$\max(a_1, a_2, \dots, a_n)$$$.You have to answer $$$t$$$ independent test cases. | For each test case, print the answer: $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the $$$i$$$-th element of the required array. If there are several answers, you can print any (it also means that the order of elements doesn't matter). It can be proven that such an array always exists under the given constraints. | C | ca9d97e731e86cf8223520f39ef5d945 | e1f9d715119be901164ee9e632c27491 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"number theory",
"brute force",
"math"
] | 1599230100 | ["5\n2 1 49\n5 20 50\n6 20 50\n5 3 8\n9 13 22"] | null | PASSED | 1,200 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$2 \le n \le 50$$$; $$$1 \le x < y \le 50$$$) — the length of the array and two elements that are present in the array, respectively. | ["1 49 \n20 40 30 50 10\n26 32 20 38 44 50 \n8 23 18 13 3 \n1 10 13 4 19 22 25 16 7"] | #include <stdio.h>
int a[55];
int main(){
int t,n,x,y,d,m,i,start,b,cnt,z;
scanf("%d",&t);
while(t--){
scanf("%d%d%d",&n,&x,&y);
d=y-x;
for(i=1;i<=d;i++)//寻找排序后,相邻两元素间距
if(d%i==0&&d/i-1+2<=n)break;//详见样例模拟
cnt=0;
z=y;
a[++cnt]=z;
while(cnt<n){//向下拓展,比y小
if(z-i<=0)break;
z-=i;
a[++cnt]=z;
}
z=y;
while(cnt<n)z+=i,a[++cnt]=z;//向上拓展,比y大
printf("%d",a[1]);
for(i=2;i<=n;i++)printf(" %d",a[i]);
printf("\n");
}
return 0;
} | |
We have a secret array. You don't know this array and you have to restore it. However, you know some facts about this array: The array consists of $$$n$$$ distinct positive (greater than $$$0$$$) integers. The array contains two elements $$$x$$$ and $$$y$$$ (these elements are known for you) such that $$$x < y$$$. If you sort the array in increasing order (such that $$$a_1 < a_2 < \ldots < a_n$$$), differences between all adjacent (consecutive) elements are equal (i.e. $$$a_2 - a_1 = a_3 - a_2 = \ldots = a_n - a_{n-1})$$$. It can be proven that such an array always exists under the constraints given below.Among all possible arrays that satisfy the given conditions, we ask you to restore one which has the minimum possible maximum element. In other words, you have to minimize $$$\max(a_1, a_2, \dots, a_n)$$$.You have to answer $$$t$$$ independent test cases. | For each test case, print the answer: $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the $$$i$$$-th element of the required array. If there are several answers, you can print any (it also means that the order of elements doesn't matter). It can be proven that such an array always exists under the given constraints. | C | ca9d97e731e86cf8223520f39ef5d945 | de4ba60bbed9444e4ad13833d97ed276 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"number theory",
"brute force",
"math"
] | 1599230100 | ["5\n2 1 49\n5 20 50\n6 20 50\n5 3 8\n9 13 22"] | null | PASSED | 1,200 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$2 \le n \le 50$$$; $$$1 \le x < y \le 50$$$) — the length of the array and two elements that are present in the array, respectively. | ["1 49 \n20 40 30 50 10\n26 32 20 38 44 50 \n8 23 18 13 3 \n1 10 13 4 19 22 25 16 7"] | #include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
void solve(int N, int X, int Y, int* s, int* d)
{
int dist = Y - X;
int tmp_s;
int tmp_d;
int min = 2147483647;
int i;
for(i=1;i<=N-1;i++)
{
if( dist % i == 0 )
{
tmp_d = dist / i;
tmp_s = Y - (tmp_d*(N-1));
while(tmp_s <= 0)
{
tmp_s += tmp_d;
}
}
if( (tmp_s + tmp_d*(N-1)) < min)
{
*s = tmp_s;
*d = tmp_d;
min = (tmp_s + tmp_d*(N-1));
}
}
}
int main()
{
// variable in description
int T;
int N;
int X;
int Y;
// variable to support
int ans;
int s;
int d;
// variable to judge
int i;
int j;
int k;
scanf("%d",&T);
for(i=0;i<T;i++)
{
scanf("%d %d %d",&N,&X,&Y);
solve(N, X, Y, &s, &d);
for(j=0;j<N;j++)
{
printf("%d ",s+j*d);
}
printf("\n");
}
return 0;
}
| |
We have a secret array. You don't know this array and you have to restore it. However, you know some facts about this array: The array consists of $$$n$$$ distinct positive (greater than $$$0$$$) integers. The array contains two elements $$$x$$$ and $$$y$$$ (these elements are known for you) such that $$$x < y$$$. If you sort the array in increasing order (such that $$$a_1 < a_2 < \ldots < a_n$$$), differences between all adjacent (consecutive) elements are equal (i.e. $$$a_2 - a_1 = a_3 - a_2 = \ldots = a_n - a_{n-1})$$$. It can be proven that such an array always exists under the constraints given below.Among all possible arrays that satisfy the given conditions, we ask you to restore one which has the minimum possible maximum element. In other words, you have to minimize $$$\max(a_1, a_2, \dots, a_n)$$$.You have to answer $$$t$$$ independent test cases. | For each test case, print the answer: $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the $$$i$$$-th element of the required array. If there are several answers, you can print any (it also means that the order of elements doesn't matter). It can be proven that such an array always exists under the given constraints. | C | ca9d97e731e86cf8223520f39ef5d945 | f5ada7c4cbe3aa98138fd2dafc5876e1 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"number theory",
"brute force",
"math"
] | 1599230100 | ["5\n2 1 49\n5 20 50\n6 20 50\n5 3 8\n9 13 22"] | null | PASSED | 1,200 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$2 \le n \le 50$$$; $$$1 \le x < y \le 50$$$) — the length of the array and two elements that are present in the array, respectively. | ["1 49 \n20 40 30 50 10\n26 32 20 38 44 50 \n8 23 18 13 3 \n1 10 13 4 19 22 25 16 7"] | #include<stdio.h>
int main()
{
// freopen("/home/shadhin/Desktop/code/IO/input.txt", "r", stdin);
// freopen("/home/shadhin/Desktop/code/IO/output.txt", "w", stdout);
int x, y, n, i, j, dif, value, res[55], output[55], difout, xin, t;
scanf("%d", &t);
while(t--)
{
scanf("%d %d %d", &n, &x, &y);
for(i=0;i<51;i++)
{
res[i]=0;
output[i]=0;
}
dif=y-x;
while(dif!=0)
{
value=y, xin=0;
for(i=n-1;i>=0;i--)
{
if(value==x)
xin=1;
res[i]=value;
value-=dif;
if(value<1)
break;
}
if(xin==1)
{
for(j=0;j<n;j++)
output[j]=res[j];
difout=dif;
}
dif--;
}
value=y;
for(i=0;i<n;i++)
{
if(output[i]==0)
{
value+=difout;
output[i]=value;
}
}
for(j=0;j<n;j++)
printf("%d ", output[j]);
printf("\n");
}
return 0;
}
| |
We have a secret array. You don't know this array and you have to restore it. However, you know some facts about this array: The array consists of $$$n$$$ distinct positive (greater than $$$0$$$) integers. The array contains two elements $$$x$$$ and $$$y$$$ (these elements are known for you) such that $$$x < y$$$. If you sort the array in increasing order (such that $$$a_1 < a_2 < \ldots < a_n$$$), differences between all adjacent (consecutive) elements are equal (i.e. $$$a_2 - a_1 = a_3 - a_2 = \ldots = a_n - a_{n-1})$$$. It can be proven that such an array always exists under the constraints given below.Among all possible arrays that satisfy the given conditions, we ask you to restore one which has the minimum possible maximum element. In other words, you have to minimize $$$\max(a_1, a_2, \dots, a_n)$$$.You have to answer $$$t$$$ independent test cases. | For each test case, print the answer: $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the $$$i$$$-th element of the required array. If there are several answers, you can print any (it also means that the order of elements doesn't matter). It can be proven that such an array always exists under the given constraints. | C | ca9d97e731e86cf8223520f39ef5d945 | 8971171a0cefb92e75f1666336428077 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"number theory",
"brute force",
"math"
] | 1599230100 | ["5\n2 1 49\n5 20 50\n6 20 50\n5 3 8\n9 13 22"] | null | PASSED | 1,200 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$2 \le n \le 50$$$; $$$1 \le x < y \le 50$$$) — the length of the array and two elements that are present in the array, respectively. | ["1 49 \n20 40 30 50 10\n26 32 20 38 44 50 \n8 23 18 13 3 \n1 10 13 4 19 22 25 16 7"] | #include <stdio.h>
int main()
{
int t;
scanf("%d", &t);
for(int k=0; k<t; ++k)
{
int x, y, n;
scanf("%d %d %d", &n, &x, &y);
int ans[n];
if(n==2)
{
ans[0]=x;
ans[1]=y;
}
else
{
int temp, temp2;
if(y>x)
{
temp=y;
y=x;
x=temp;
}
for(int i=n-1; i>=0; --i)
{
temp=(x-y)/i;
if((x-y)==temp*i)
{
temp2=i;
break;
}
}
if(temp2==n-1)
{
for(int i=0; i<n; ++i)
{
ans[i]=y;
y=y+temp;
}
}
else
{
int count=0;
temp2=y;
while(temp2<=x && count<n)
{
ans[count++]=temp2;
temp2+=temp;
}
temp2=y-temp;
while(temp2>0 && count<n)
{
ans[count++]=temp2;
temp2-=temp;
}
temp2=x+temp;
while(count<n)
{
ans[count++]=temp2;
temp2+=temp;
}
}
}
for(int i=0; i<n; i++)
{
printf("%d ", ans[i]);
}
printf("\n");
}
return 0;
} | |
We have a secret array. You don't know this array and you have to restore it. However, you know some facts about this array: The array consists of $$$n$$$ distinct positive (greater than $$$0$$$) integers. The array contains two elements $$$x$$$ and $$$y$$$ (these elements are known for you) such that $$$x < y$$$. If you sort the array in increasing order (such that $$$a_1 < a_2 < \ldots < a_n$$$), differences between all adjacent (consecutive) elements are equal (i.e. $$$a_2 - a_1 = a_3 - a_2 = \ldots = a_n - a_{n-1})$$$. It can be proven that such an array always exists under the constraints given below.Among all possible arrays that satisfy the given conditions, we ask you to restore one which has the minimum possible maximum element. In other words, you have to minimize $$$\max(a_1, a_2, \dots, a_n)$$$.You have to answer $$$t$$$ independent test cases. | For each test case, print the answer: $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the $$$i$$$-th element of the required array. If there are several answers, you can print any (it also means that the order of elements doesn't matter). It can be proven that such an array always exists under the given constraints. | C | ca9d97e731e86cf8223520f39ef5d945 | feb04a6a5fa9617b722c759d6bddc771 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"number theory",
"brute force",
"math"
] | 1599230100 | ["5\n2 1 49\n5 20 50\n6 20 50\n5 3 8\n9 13 22"] | null | PASSED | 1,200 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$2 \le n \le 50$$$; $$$1 \le x < y \le 50$$$) — the length of the array and two elements that are present in the array, respectively. | ["1 49 \n20 40 30 50 10\n26 32 20 38 44 50 \n8 23 18 13 3 \n1 10 13 4 19 22 25 16 7"] | #include <stdio.h>
int main()
{
int t,i;
scanf("%d",&t);
for(i=0;i<t;i++)
{ int n,x,y,j,k,l,d,o,u;
scanf("%d %d %d",&n,&x,&y);
for(j=n-1;j>0;j--)
{
if((y-x)%j==0)
break;
}
u=y;
d=(y-x)/j;
for(k=0;k<n;k++,y=y-d)
{
if(y>0)
printf("%d ",y);
else break;
}
for(l=k,o=1;l<n;l++,o++)
printf("%d ",u+o*d);
printf("\n");
}
}
| |
We have a secret array. You don't know this array and you have to restore it. However, you know some facts about this array: The array consists of $$$n$$$ distinct positive (greater than $$$0$$$) integers. The array contains two elements $$$x$$$ and $$$y$$$ (these elements are known for you) such that $$$x < y$$$. If you sort the array in increasing order (such that $$$a_1 < a_2 < \ldots < a_n$$$), differences between all adjacent (consecutive) elements are equal (i.e. $$$a_2 - a_1 = a_3 - a_2 = \ldots = a_n - a_{n-1})$$$. It can be proven that such an array always exists under the constraints given below.Among all possible arrays that satisfy the given conditions, we ask you to restore one which has the minimum possible maximum element. In other words, you have to minimize $$$\max(a_1, a_2, \dots, a_n)$$$.You have to answer $$$t$$$ independent test cases. | For each test case, print the answer: $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the $$$i$$$-th element of the required array. If there are several answers, you can print any (it also means that the order of elements doesn't matter). It can be proven that such an array always exists under the given constraints. | C | ca9d97e731e86cf8223520f39ef5d945 | 4f18511b138909865f4204082e7252b3 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"number theory",
"brute force",
"math"
] | 1599230100 | ["5\n2 1 49\n5 20 50\n6 20 50\n5 3 8\n9 13 22"] | null | PASSED | 1,200 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$2 \le n \le 50$$$; $$$1 \le x < y \le 50$$$) — the length of the array and two elements that are present in the array, respectively. | ["1 49 \n20 40 30 50 10\n26 32 20 38 44 50 \n8 23 18 13 3 \n1 10 13 4 19 22 25 16 7"] | #include <stdio.h>
int main(void){
int T;
long long i, j, n, x, y, tmp, cnt, flag;
scanf("%d", &T);
while(T--){
scanf("%lld %lld %lld", &n, &x, &y);
if(n==2){
printf("%lld %lld\n", x, y);
}
else{
flag=0;
for(i=1; i<=50; ++i){
if(x%i==y%i){
tmp=i;
for(j=1; j<n; ++j){
if(x+i*j==y){
flag=1;
break;
}
}
if(flag){
break;
}
}
}
cnt=0;
for(i=y; i>=1 && cnt<n; i-=tmp){
printf("%lld ", i);
++cnt;
}
i=y+tmp;
while(cnt<n){
printf("%lld ", i);
i+=tmp;
++cnt;
}
printf("\n");
}
}
return 0;
}
| |
We have a secret array. You don't know this array and you have to restore it. However, you know some facts about this array: The array consists of $$$n$$$ distinct positive (greater than $$$0$$$) integers. The array contains two elements $$$x$$$ and $$$y$$$ (these elements are known for you) such that $$$x < y$$$. If you sort the array in increasing order (such that $$$a_1 < a_2 < \ldots < a_n$$$), differences between all adjacent (consecutive) elements are equal (i.e. $$$a_2 - a_1 = a_3 - a_2 = \ldots = a_n - a_{n-1})$$$. It can be proven that such an array always exists under the constraints given below.Among all possible arrays that satisfy the given conditions, we ask you to restore one which has the minimum possible maximum element. In other words, you have to minimize $$$\max(a_1, a_2, \dots, a_n)$$$.You have to answer $$$t$$$ independent test cases. | For each test case, print the answer: $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the $$$i$$$-th element of the required array. If there are several answers, you can print any (it also means that the order of elements doesn't matter). It can be proven that such an array always exists under the given constraints. | C | ca9d97e731e86cf8223520f39ef5d945 | 1613ce6f8bf07b5c8e491c58d0accb84 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"number theory",
"brute force",
"math"
] | 1599230100 | ["5\n2 1 49\n5 20 50\n6 20 50\n5 3 8\n9 13 22"] | null | PASSED | 1,200 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$2 \le n \le 50$$$; $$$1 \le x < y \le 50$$$) — the length of the array and two elements that are present in the array, respectively. | ["1 49 \n20 40 30 50 10\n26 32 20 38 44 50 \n8 23 18 13 3 \n1 10 13 4 19 22 25 16 7"] | #include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
int x,y,a,b,i,j,m,n,t,ans,det,det2;
scanf("%d", &t);
while(t--){
scanf("%d%d%d", &n,&x,&y);
m=n;
int sub,cnt=0;
det2=x;
det=y-x;
n--;
while(n>=1){
if(det%n==0){
ans=det/n;
break;
}
n--;
}
printf("%d ", x);
for(i=1;i<=n;i++){
printf("%d ", x+ans);
if(i<n)x+=ans;
}
sub=m-(n+1);
x=det2;
for(i=1;i<=sub;i++){
if(x-ans>0){
printf("%d ", x-ans);
cnt++;
}
else break;
x-=ans;
}
sub-=cnt;
//printf("sub=%d\n", sub);
for(i=1;i<=sub;i++){
printf("%d ", y+ans);
y+=ans;
}
printf("\n");
}
return 0;
}
| |
We have a secret array. You don't know this array and you have to restore it. However, you know some facts about this array: The array consists of $$$n$$$ distinct positive (greater than $$$0$$$) integers. The array contains two elements $$$x$$$ and $$$y$$$ (these elements are known for you) such that $$$x < y$$$. If you sort the array in increasing order (such that $$$a_1 < a_2 < \ldots < a_n$$$), differences between all adjacent (consecutive) elements are equal (i.e. $$$a_2 - a_1 = a_3 - a_2 = \ldots = a_n - a_{n-1})$$$. It can be proven that such an array always exists under the constraints given below.Among all possible arrays that satisfy the given conditions, we ask you to restore one which has the minimum possible maximum element. In other words, you have to minimize $$$\max(a_1, a_2, \dots, a_n)$$$.You have to answer $$$t$$$ independent test cases. | For each test case, print the answer: $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the $$$i$$$-th element of the required array. If there are several answers, you can print any (it also means that the order of elements doesn't matter). It can be proven that such an array always exists under the given constraints. | C | ca9d97e731e86cf8223520f39ef5d945 | f8cd9c30fbf4dd614997c997f70c6680 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"number theory",
"brute force",
"math"
] | 1599230100 | ["5\n2 1 49\n5 20 50\n6 20 50\n5 3 8\n9 13 22"] | null | PASSED | 1,200 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$2 \le n \le 50$$$; $$$1 \le x < y \le 50$$$) — the length of the array and two elements that are present in the array, respectively. | ["1 49 \n20 40 30 50 10\n26 32 20 38 44 50 \n8 23 18 13 3 \n1 10 13 4 19 22 25 16 7"] | #include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>
int Func(int j,int n)
{
int i;
for(i=1;i<=50;i++)
{
if(j%i==0)
{
if(j/i<=n-1)
{
return i;
}
}
}
}
int Func2(int y,int i,int n)
{
if(y/i>=n-1)
{
if(y-(n-1)*i==0)
{
return i;
}
return y-(n-1)*i;
}
else
{
if(y-(y/i)*i==0)
{
return i;
}
return y-(y/i)*i;
}
}
int main()
{
int T,i;
scanf("%d",&T);
for(i=0;i<T;i++)
{
int n,x,y,j,k,l,m;
scanf("%d%d%d",&n,&x,&y);
j=y-x;
k=Func(j,n);
//printf("k%d\n",k);
l=Func2(y,k,n);
m=0;
while(m<n)
{
printf("%d ",l);
l=l+k;
m=m+1;
}
printf("\n");
}
} | |
We have a secret array. You don't know this array and you have to restore it. However, you know some facts about this array: The array consists of $$$n$$$ distinct positive (greater than $$$0$$$) integers. The array contains two elements $$$x$$$ and $$$y$$$ (these elements are known for you) such that $$$x < y$$$. If you sort the array in increasing order (such that $$$a_1 < a_2 < \ldots < a_n$$$), differences between all adjacent (consecutive) elements are equal (i.e. $$$a_2 - a_1 = a_3 - a_2 = \ldots = a_n - a_{n-1})$$$. It can be proven that such an array always exists under the constraints given below.Among all possible arrays that satisfy the given conditions, we ask you to restore one which has the minimum possible maximum element. In other words, you have to minimize $$$\max(a_1, a_2, \dots, a_n)$$$.You have to answer $$$t$$$ independent test cases. | For each test case, print the answer: $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the $$$i$$$-th element of the required array. If there are several answers, you can print any (it also means that the order of elements doesn't matter). It can be proven that such an array always exists under the given constraints. | C | ca9d97e731e86cf8223520f39ef5d945 | 49c0899ce2588eba385115dccc1fd81f | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"number theory",
"brute force",
"math"
] | 1599230100 | ["5\n2 1 49\n5 20 50\n6 20 50\n5 3 8\n9 13 22"] | null | PASSED | 1,200 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$2 \le n \le 50$$$; $$$1 \le x < y \le 50$$$) — the length of the array and two elements that are present in the array, respectively. | ["1 49 \n20 40 30 50 10\n26 32 20 38 44 50 \n8 23 18 13 3 \n1 10 13 4 19 22 25 16 7"] | #include <stdio.h>
int main() {
int t;
scanf("%d", &t);
while(t--) {
int n, x, y, temp;
scanf("%d %d %d", &n, &x, &y);
if(n == 2) { printf("%d %d\n", x, y); }
else {
int r = y - x;
int temp = 0, id, j;
for(int i = 2; i <= n - 1; i++) {
if(r % i == 0) { temp = r / i; id = i; }
}
if(temp == 0) { temp = r; id = 1; }
int rem = n - (id + 1);
int x2 = x;
for(int i = 0; i <= id; i++) { printf("%d ", x); x += temp; }
if(rem > 0) {
int dif = (x - 1) / temp;
if(dif >= 1) {
for(int i = 1; i <= dif; i++) {
x2 -= temp;
if(rem <= 0 || x2 <= 0) { break; }
else {
printf("%d ", x2);
rem--;
}
}
}
while(rem > 0) {
if(rem <= 0) { break; }
else {
y += temp;
printf("%d ", y);
rem--;
}
}
}
printf("\n");
}
}
return 0;
}
| |
We have a secret array. You don't know this array and you have to restore it. However, you know some facts about this array: The array consists of $$$n$$$ distinct positive (greater than $$$0$$$) integers. The array contains two elements $$$x$$$ and $$$y$$$ (these elements are known for you) such that $$$x < y$$$. If you sort the array in increasing order (such that $$$a_1 < a_2 < \ldots < a_n$$$), differences between all adjacent (consecutive) elements are equal (i.e. $$$a_2 - a_1 = a_3 - a_2 = \ldots = a_n - a_{n-1})$$$. It can be proven that such an array always exists under the constraints given below.Among all possible arrays that satisfy the given conditions, we ask you to restore one which has the minimum possible maximum element. In other words, you have to minimize $$$\max(a_1, a_2, \dots, a_n)$$$.You have to answer $$$t$$$ independent test cases. | For each test case, print the answer: $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the $$$i$$$-th element of the required array. If there are several answers, you can print any (it also means that the order of elements doesn't matter). It can be proven that such an array always exists under the given constraints. | C | ca9d97e731e86cf8223520f39ef5d945 | 0852b105882588c87ec76725e178ad40 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"number theory",
"brute force",
"math"
] | 1599230100 | ["5\n2 1 49\n5 20 50\n6 20 50\n5 3 8\n9 13 22"] | null | PASSED | 1,200 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$2 \le n \le 50$$$; $$$1 \le x < y \le 50$$$) — the length of the array and two elements that are present in the array, respectively. | ["1 49 \n20 40 30 50 10\n26 32 20 38 44 50 \n8 23 18 13 3 \n1 10 13 4 19 22 25 16 7"] | #include<stdio.h>
void main()
{
int t;
scanf("%i",&t);
while(t--)
{
int n,x,y;
scanf("%i %i %i",&n,&x,&y);
if(n==2)
printf("%i %i\n",x,y);
else
{
int index=0;
long long int a[n];
int cn=n-1,cx=x,cy=y;
while(cn>1)
{
if((y-x)%cn==0)
break;
cn--;
}
if(cn!=1)
{
int diff=(y-x)/cn;
int dn=n;
while(dn!=0)
{
a[index++]=cy;
cy-=diff;
if(cy<=0)
{
cy=y+diff;
diff*=(-1);
}
dn--;
}
}
else if(cn==1)
{
if(n>(y-x))
{
int diff=1;
int dn=n;
while(dn!=0)
{
a[index++]=cy;
cy-=diff;
if(cy<=0)
{
cy=y+diff;
diff*=(-1);
}
dn--;
}
}
else
{
int diff=(y-x)/cn;
int dn=n;
while(dn!=0)
{
a[index++]=cy;
cy-=diff;
if(cy<=0)
{
cy=y+diff;
diff*=(-1);
}
dn--;
}
}
}
for(int i=0;i<n;i++)
printf("%lli ",a[i]);
printf("\n");
}
}
}
| |
We have a secret array. You don't know this array and you have to restore it. However, you know some facts about this array: The array consists of $$$n$$$ distinct positive (greater than $$$0$$$) integers. The array contains two elements $$$x$$$ and $$$y$$$ (these elements are known for you) such that $$$x < y$$$. If you sort the array in increasing order (such that $$$a_1 < a_2 < \ldots < a_n$$$), differences between all adjacent (consecutive) elements are equal (i.e. $$$a_2 - a_1 = a_3 - a_2 = \ldots = a_n - a_{n-1})$$$. It can be proven that such an array always exists under the constraints given below.Among all possible arrays that satisfy the given conditions, we ask you to restore one which has the minimum possible maximum element. In other words, you have to minimize $$$\max(a_1, a_2, \dots, a_n)$$$.You have to answer $$$t$$$ independent test cases. | For each test case, print the answer: $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the $$$i$$$-th element of the required array. If there are several answers, you can print any (it also means that the order of elements doesn't matter). It can be proven that such an array always exists under the given constraints. | C | ca9d97e731e86cf8223520f39ef5d945 | b7b0aff35f4e00f5fff14246d5419a73 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"number theory",
"brute force",
"math"
] | 1599230100 | ["5\n2 1 49\n5 20 50\n6 20 50\n5 3 8\n9 13 22"] | null | PASSED | 1,200 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$2 \le n \le 50$$$; $$$1 \le x < y \le 50$$$) — the length of the array and two elements that are present in the array, respectively. | ["1 49 \n20 40 30 50 10\n26 32 20 38 44 50 \n8 23 18 13 3 \n1 10 13 4 19 22 25 16 7"] | #include <stdio.h>
int main(int argc, char *argv[])
{
int tc;
scanf("%d",&tc);
while(tc--){
int n,x,y;
scanf("%d%d%d",&n,&x,&y);
int a[3000]={0},c=0;
int d,i,j,ans,st;
d=y-x;
for(i=1;i<=d;i++){
if(d%i==0){
ans=(d/i)-1;
if(ans>(n-2))
continue;
else break;
}
}
st=y-(n-1)*i;
while(st<=0)st+=i;
st-=i;
for(j=0;j<n;j++)
printf("%d ",st+=i);
printf("\n");
}
} | |
We have a secret array. You don't know this array and you have to restore it. However, you know some facts about this array: The array consists of $$$n$$$ distinct positive (greater than $$$0$$$) integers. The array contains two elements $$$x$$$ and $$$y$$$ (these elements are known for you) such that $$$x < y$$$. If you sort the array in increasing order (such that $$$a_1 < a_2 < \ldots < a_n$$$), differences between all adjacent (consecutive) elements are equal (i.e. $$$a_2 - a_1 = a_3 - a_2 = \ldots = a_n - a_{n-1})$$$. It can be proven that such an array always exists under the constraints given below.Among all possible arrays that satisfy the given conditions, we ask you to restore one which has the minimum possible maximum element. In other words, you have to minimize $$$\max(a_1, a_2, \dots, a_n)$$$.You have to answer $$$t$$$ independent test cases. | For each test case, print the answer: $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the $$$i$$$-th element of the required array. If there are several answers, you can print any (it also means that the order of elements doesn't matter). It can be proven that such an array always exists under the given constraints. | C | ca9d97e731e86cf8223520f39ef5d945 | 6e7f684e16edb74f796aaa043b6f5690 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"number theory",
"brute force",
"math"
] | 1599230100 | ["5\n2 1 49\n5 20 50\n6 20 50\n5 3 8\n9 13 22"] | null | PASSED | 1,200 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$2 \le n \le 50$$$; $$$1 \le x < y \le 50$$$) — the length of the array and two elements that are present in the array, respectively. | ["1 49 \n20 40 30 50 10\n26 32 20 38 44 50 \n8 23 18 13 3 \n1 10 13 4 19 22 25 16 7"] | #include<stdio.h>
int main(){
int t;
scanf("%d",&t);
while(t--){
int i,n,x,y;
scanf("%d%d%d",&n,&x,&y);
int m,cha,z=1,a[51];
for(i=0;i<51;i++)a[i]=0;
m=y;
cha=y-x;
for(i=1;i<=cha;i++){
if(cha%i==0&&cha/i+1<=n)break;
}
a[1]=y;
while(z+1<=n){
m-=i;
if(m<=0)break;
a[++z]=m;
}
m=y;
while(z+1<=n){
m+=i;
a[++z]=m;
}
for(i=0;i<51;i++){
if(a[i]!=0)printf("%d ",a[i]);
}
printf("\n");
}
} | |
We have a secret array. You don't know this array and you have to restore it. However, you know some facts about this array: The array consists of $$$n$$$ distinct positive (greater than $$$0$$$) integers. The array contains two elements $$$x$$$ and $$$y$$$ (these elements are known for you) such that $$$x < y$$$. If you sort the array in increasing order (such that $$$a_1 < a_2 < \ldots < a_n$$$), differences between all adjacent (consecutive) elements are equal (i.e. $$$a_2 - a_1 = a_3 - a_2 = \ldots = a_n - a_{n-1})$$$. It can be proven that such an array always exists under the constraints given below.Among all possible arrays that satisfy the given conditions, we ask you to restore one which has the minimum possible maximum element. In other words, you have to minimize $$$\max(a_1, a_2, \dots, a_n)$$$.You have to answer $$$t$$$ independent test cases. | For each test case, print the answer: $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the $$$i$$$-th element of the required array. If there are several answers, you can print any (it also means that the order of elements doesn't matter). It can be proven that such an array always exists under the given constraints. | C | ca9d97e731e86cf8223520f39ef5d945 | dc942ffa7e6bd62bd0118ad989f73e00 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"number theory",
"brute force",
"math"
] | 1599230100 | ["5\n2 1 49\n5 20 50\n6 20 50\n5 3 8\n9 13 22"] | null | PASSED | 1,200 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$2 \le n \le 50$$$; $$$1 \le x < y \le 50$$$) — the length of the array and two elements that are present in the array, respectively. | ["1 49 \n20 40 30 50 10\n26 32 20 38 44 50 \n8 23 18 13 3 \n1 10 13 4 19 22 25 16 7"] | #include <stdio.h>
typedef long long ll;
void swap(ll *a, ll *b)
{
ll temp = *a;
*a = *b;
*b = temp;
}
/*void quicksort(int arr[], int l, int r)
{
if (l >= r)
{
return;
}
int pivot = arr[r];
int cnt = l;
for (int i = l; i <= r; i++)
{
if (arr[i] <= pivot)
{
swap(&arr[cnt], &arr[i]);
cnt++;
}
}
quicksort(arr, l, cnt-2);
quicksort(arr, cnt, r);
}*/
int main()
{
ll t,x,y,n;
scanf("%lld",&t);
while(t--)
{
ll i=1;
scanf("%lld %lld %lld",&n,&x,&y);
for(i=1;i<(y-x+1);i++)
{
ll no=(y-x);
if(no%i!=0)
continue;
else
{
no=no/i+1;
if(no>n)
continue;
else if(no==n)
{
for(ll j=0;j<n;j++)
{
printf("%lld ",x);
x=x+i;
}
printf("\n");
break;
}
else
{
ll no2=x,no1=(y-x)/i;
n=n-no1;;
while(no2>0 && n>0)
{
printf("%lld ",no2);
no2=no2-i;
n--;
}
no2=x+i;
n+=no1;
while(n>0)
{
printf("%lld ",no2);
no2+=i;
n--;
}
printf("\n");
break;
}
}
}
}
return 0;
}
| |
We have a secret array. You don't know this array and you have to restore it. However, you know some facts about this array: The array consists of $$$n$$$ distinct positive (greater than $$$0$$$) integers. The array contains two elements $$$x$$$ and $$$y$$$ (these elements are known for you) such that $$$x < y$$$. If you sort the array in increasing order (such that $$$a_1 < a_2 < \ldots < a_n$$$), differences between all adjacent (consecutive) elements are equal (i.e. $$$a_2 - a_1 = a_3 - a_2 = \ldots = a_n - a_{n-1})$$$. It can be proven that such an array always exists under the constraints given below.Among all possible arrays that satisfy the given conditions, we ask you to restore one which has the minimum possible maximum element. In other words, you have to minimize $$$\max(a_1, a_2, \dots, a_n)$$$.You have to answer $$$t$$$ independent test cases. | For each test case, print the answer: $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the $$$i$$$-th element of the required array. If there are several answers, you can print any (it also means that the order of elements doesn't matter). It can be proven that such an array always exists under the given constraints. | C | ca9d97e731e86cf8223520f39ef5d945 | c464e2389ecdc386736f7af5fde15c48 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"number theory",
"brute force",
"math"
] | 1599230100 | ["5\n2 1 49\n5 20 50\n6 20 50\n5 3 8\n9 13 22"] | null | PASSED | 1,200 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$2 \le n \le 50$$$; $$$1 \le x < y \le 50$$$) — the length of the array and two elements that are present in the array, respectively. | ["1 49 \n20 40 30 50 10\n26 32 20 38 44 50 \n8 23 18 13 3 \n1 10 13 4 19 22 25 16 7"] | #include<stdio.h>
int main(){long int t,i,n,x,y,j,c,k,h,y1;
scanf("%ld",&t);
for(i=0;i<t;i++)
{
scanf("%ld%ld%ld",&n,&x,&y);
c=0;
for(j=n-1;j>=1;j--)
{
if((y-x)%j==0)
{
c++;
break;
}
}
if(c==0)
{
k=0;
h=y-x;
y1=y;
while(y>0&&k<n)
{
printf("%ld ",y);
y=y-h;
k++;
}
for(j=0;j<n-k;j++)
{
printf("%ld ",y1+h);
y1=y1+h;
}
printf("\n");
}
else
{
k=0;
h=(y-x)/j;
y1=y;
while(y>0&&k<n)
{
printf("%ld ",y);
y=y-h;
k++;
}
for(j=0;j<n-k;j++)
{
printf("%ld ",y1+h);
y1=y1+h;
}
printf("\n");
}
}
return 0;
}
| |
We have a secret array. You don't know this array and you have to restore it. However, you know some facts about this array: The array consists of $$$n$$$ distinct positive (greater than $$$0$$$) integers. The array contains two elements $$$x$$$ and $$$y$$$ (these elements are known for you) such that $$$x < y$$$. If you sort the array in increasing order (such that $$$a_1 < a_2 < \ldots < a_n$$$), differences between all adjacent (consecutive) elements are equal (i.e. $$$a_2 - a_1 = a_3 - a_2 = \ldots = a_n - a_{n-1})$$$. It can be proven that such an array always exists under the constraints given below.Among all possible arrays that satisfy the given conditions, we ask you to restore one which has the minimum possible maximum element. In other words, you have to minimize $$$\max(a_1, a_2, \dots, a_n)$$$.You have to answer $$$t$$$ independent test cases. | For each test case, print the answer: $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the $$$i$$$-th element of the required array. If there are several answers, you can print any (it also means that the order of elements doesn't matter). It can be proven that such an array always exists under the given constraints. | C | ca9d97e731e86cf8223520f39ef5d945 | e8cef4b21fbdecf50023babe3b650967 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"number theory",
"brute force",
"math"
] | 1599230100 | ["5\n2 1 49\n5 20 50\n6 20 50\n5 3 8\n9 13 22"] | null | PASSED | 1,200 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$2 \le n \le 50$$$; $$$1 \le x < y \le 50$$$) — the length of the array and two elements that are present in the array, respectively. | ["1 49 \n20 40 30 50 10\n26 32 20 38 44 50 \n8 23 18 13 3 \n1 10 13 4 19 22 25 16 7"] | #include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <limits.h>
int main() {
int t;
scanf("%d", &t);
for (int tt = 0; tt < t; ++tt) {
int n, x, y;
scanf("%d %d %d", &n, &x, &y);
int sorozat[50] = {0};
int legnagyobb = INT_MAX;
for (int elso_szam = 1; elso_szam <= x; ++elso_szam) {
for (int r = 1; r <= y - x; ++r) {
bool talalt_x = false;
bool talalt_y = false;
int tomb[50] = {0};
for (int i = 0; i < n; ++i) {
int szam = elso_szam + i * r;
tomb[i] = szam;
if (szam == x)
talalt_x = true;
else if (szam == y)
talalt_y = true;
}
if (talalt_x && talalt_y && tomb[n - 1] < legnagyobb) {
legnagyobb = tomb[n - 1];
for (int i = 0; i < n; ++i)
sorozat[i] = tomb[i];
}
}
}
for (int i = 0; i < n; ++i)
printf("%d ", sorozat[i]);
printf("\n");
}
return 0;
}
| |
We have a secret array. You don't know this array and you have to restore it. However, you know some facts about this array: The array consists of $$$n$$$ distinct positive (greater than $$$0$$$) integers. The array contains two elements $$$x$$$ and $$$y$$$ (these elements are known for you) such that $$$x < y$$$. If you sort the array in increasing order (such that $$$a_1 < a_2 < \ldots < a_n$$$), differences between all adjacent (consecutive) elements are equal (i.e. $$$a_2 - a_1 = a_3 - a_2 = \ldots = a_n - a_{n-1})$$$. It can be proven that such an array always exists under the constraints given below.Among all possible arrays that satisfy the given conditions, we ask you to restore one which has the minimum possible maximum element. In other words, you have to minimize $$$\max(a_1, a_2, \dots, a_n)$$$.You have to answer $$$t$$$ independent test cases. | For each test case, print the answer: $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the $$$i$$$-th element of the required array. If there are several answers, you can print any (it also means that the order of elements doesn't matter). It can be proven that such an array always exists under the given constraints. | C | ca9d97e731e86cf8223520f39ef5d945 | ccb6af4c72ed60ddac10db84ff4523e2 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"number theory",
"brute force",
"math"
] | 1599230100 | ["5\n2 1 49\n5 20 50\n6 20 50\n5 3 8\n9 13 22"] | null | PASSED | 1,200 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$2 \le n \le 50$$$; $$$1 \le x < y \le 50$$$) — the length of the array and two elements that are present in the array, respectively. | ["1 49 \n20 40 30 50 10\n26 32 20 38 44 50 \n8 23 18 13 3 \n1 10 13 4 19 22 25 16 7"] | #include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define min(a,b) a>b?:b,a
int main(){
int t;
scanf("%d",&t);
int a[50];
while(t--){
int x,y,n,o,a,d;
scanf("%d %d %d",&n,&x,&y);
for(int i=n-2;i>=0;i--){
int o=y-x;
if(o==o/(i+1)*(i+1)){
d=o/(i+1);
for(int j=n-2-i;j>=0;j--)
if(x-j*d>0){
a=x-j*d;break;
}
break;
}
}
int i=0;
for(i=0;i<n-1;i++)printf("%d ",a+i*d);
printf("%d\n",a+i*d);
}
} | |
We have a secret array. You don't know this array and you have to restore it. However, you know some facts about this array: The array consists of $$$n$$$ distinct positive (greater than $$$0$$$) integers. The array contains two elements $$$x$$$ and $$$y$$$ (these elements are known for you) such that $$$x < y$$$. If you sort the array in increasing order (such that $$$a_1 < a_2 < \ldots < a_n$$$), differences between all adjacent (consecutive) elements are equal (i.e. $$$a_2 - a_1 = a_3 - a_2 = \ldots = a_n - a_{n-1})$$$. It can be proven that such an array always exists under the constraints given below.Among all possible arrays that satisfy the given conditions, we ask you to restore one which has the minimum possible maximum element. In other words, you have to minimize $$$\max(a_1, a_2, \dots, a_n)$$$.You have to answer $$$t$$$ independent test cases. | For each test case, print the answer: $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the $$$i$$$-th element of the required array. If there are several answers, you can print any (it also means that the order of elements doesn't matter). It can be proven that such an array always exists under the given constraints. | C | ca9d97e731e86cf8223520f39ef5d945 | e114bcbff2379dd46adcbbc24a209e85 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"number theory",
"brute force",
"math"
] | 1599230100 | ["5\n2 1 49\n5 20 50\n6 20 50\n5 3 8\n9 13 22"] | null | PASSED | 1,200 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$2 \le n \le 50$$$; $$$1 \le x < y \le 50$$$) — the length of the array and two elements that are present in the array, respectively. | ["1 49 \n20 40 30 50 10\n26 32 20 38 44 50 \n8 23 18 13 3 \n1 10 13 4 19 22 25 16 7"] | #include<stdio.h>
main()
{
int t; scanf("%d",&t);
while(t--)
{
int a,b,c,d,e,n,x,y; scanf("%d%d%d",&n,&x,&y);
for(b=1 ; ; b++)
for (a= 1; a<n ; a++)
{
if((y-x)==(a*b)) goto ok;
}
ok:for(c=0 ; c<n ; c++)
{
printf("%d ",b*c+x);
if((b*c+x)==y && n-1>c)
{
for(d=1 ; (d*b)<x ; d++)
{printf("%d ",x-d*b);
n--; if(n-c<=1) break;
}
}
}
printf("\n");
}
}
| |
We have a secret array. You don't know this array and you have to restore it. However, you know some facts about this array: The array consists of $$$n$$$ distinct positive (greater than $$$0$$$) integers. The array contains two elements $$$x$$$ and $$$y$$$ (these elements are known for you) such that $$$x < y$$$. If you sort the array in increasing order (such that $$$a_1 < a_2 < \ldots < a_n$$$), differences between all adjacent (consecutive) elements are equal (i.e. $$$a_2 - a_1 = a_3 - a_2 = \ldots = a_n - a_{n-1})$$$. It can be proven that such an array always exists under the constraints given below.Among all possible arrays that satisfy the given conditions, we ask you to restore one which has the minimum possible maximum element. In other words, you have to minimize $$$\max(a_1, a_2, \dots, a_n)$$$.You have to answer $$$t$$$ independent test cases. | For each test case, print the answer: $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the $$$i$$$-th element of the required array. If there are several answers, you can print any (it also means that the order of elements doesn't matter). It can be proven that such an array always exists under the given constraints. | C | ca9d97e731e86cf8223520f39ef5d945 | 55e1693a26825b13c5e7b0b3378d2d11 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"number theory",
"brute force",
"math"
] | 1599230100 | ["5\n2 1 49\n5 20 50\n6 20 50\n5 3 8\n9 13 22"] | null | PASSED | 1,200 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$2 \le n \le 50$$$; $$$1 \le x < y \le 50$$$) — the length of the array and two elements that are present in the array, respectively. | ["1 49 \n20 40 30 50 10\n26 32 20 38 44 50 \n8 23 18 13 3 \n1 10 13 4 19 22 25 16 7"] | #include<stdio.h>
int main(){
int t,x,y,n,a[50],check,i,i2,i3,i4;
scanf("%d",&t);
for (i=0;i<t;i++){
check=0;
scanf("%d %d %d",&n,&x,&y);
a[0]=y;
for (i2=1;i2<=(y-x);i2++){
for (i3=1;i3<n;i3++){
a[i3]=y-i3*i2;
if (a[i3]==x) check=1;
if (a[i3]<=0) break;
}
for (i4=0;i4<n-i3;i4++) a[i4+i3]=y+(i4+1)*i2;
if (check==1) break;
}
for (int i5=0;i5<n;i5++) {
if (i5!=n-1) printf("%d ",a[i5]);
else printf("%d\n",a[i5]);
}
}
return 0;
}
| |
We have a secret array. You don't know this array and you have to restore it. However, you know some facts about this array: The array consists of $$$n$$$ distinct positive (greater than $$$0$$$) integers. The array contains two elements $$$x$$$ and $$$y$$$ (these elements are known for you) such that $$$x < y$$$. If you sort the array in increasing order (such that $$$a_1 < a_2 < \ldots < a_n$$$), differences between all adjacent (consecutive) elements are equal (i.e. $$$a_2 - a_1 = a_3 - a_2 = \ldots = a_n - a_{n-1})$$$. It can be proven that such an array always exists under the constraints given below.Among all possible arrays that satisfy the given conditions, we ask you to restore one which has the minimum possible maximum element. In other words, you have to minimize $$$\max(a_1, a_2, \dots, a_n)$$$.You have to answer $$$t$$$ independent test cases. | For each test case, print the answer: $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the $$$i$$$-th element of the required array. If there are several answers, you can print any (it also means that the order of elements doesn't matter). It can be proven that such an array always exists under the given constraints. | C | ca9d97e731e86cf8223520f39ef5d945 | 0292446813d93d75fe45949b67a96956 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"number theory",
"brute force",
"math"
] | 1599230100 | ["5\n2 1 49\n5 20 50\n6 20 50\n5 3 8\n9 13 22"] | null | PASSED | 1,200 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$2 \le n \le 50$$$; $$$1 \le x < y \le 50$$$) — the length of the array and two elements that are present in the array, respectively. | ["1 49 \n20 40 30 50 10\n26 32 20 38 44 50 \n8 23 18 13 3 \n1 10 13 4 19 22 25 16 7"] | #include <stdio.h>
int main()
{
long long int t, n, x, y, ans;
scanf("%lld", &t);
while (t--)
{
scanf("%lld %lld %lld", &n, &x, &y);
int d = y - x;
int diff;
for (int i = 1; i <= d; i++)
{
if (d%i == 0)
{
diff = i;
if (y - (n - 1)*i <= x)
{
break;
}
}
}
int start = y - (n - 1)*diff;
while (start <= 0)
{
start += diff;
}
for (int i = 0; i<n; i++)
{
printf("%d ", start + (diff*i));
}
printf("\n");
}
return 0;
} | |
We have a secret array. You don't know this array and you have to restore it. However, you know some facts about this array: The array consists of $$$n$$$ distinct positive (greater than $$$0$$$) integers. The array contains two elements $$$x$$$ and $$$y$$$ (these elements are known for you) such that $$$x < y$$$. If you sort the array in increasing order (such that $$$a_1 < a_2 < \ldots < a_n$$$), differences between all adjacent (consecutive) elements are equal (i.e. $$$a_2 - a_1 = a_3 - a_2 = \ldots = a_n - a_{n-1})$$$. It can be proven that such an array always exists under the constraints given below.Among all possible arrays that satisfy the given conditions, we ask you to restore one which has the minimum possible maximum element. In other words, you have to minimize $$$\max(a_1, a_2, \dots, a_n)$$$.You have to answer $$$t$$$ independent test cases. | For each test case, print the answer: $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the $$$i$$$-th element of the required array. If there are several answers, you can print any (it also means that the order of elements doesn't matter). It can be proven that such an array always exists under the given constraints. | C | ca9d97e731e86cf8223520f39ef5d945 | 1fe20382dfa7c022268f550ca2289433 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"number theory",
"brute force",
"math"
] | 1599230100 | ["5\n2 1 49\n5 20 50\n6 20 50\n5 3 8\n9 13 22"] | null | PASSED | 1,200 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$2 \le n \le 50$$$; $$$1 \le x < y \le 50$$$) — the length of the array and two elements that are present in the array, respectively. | ["1 49 \n20 40 30 50 10\n26 32 20 38 44 50 \n8 23 18 13 3 \n1 10 13 4 19 22 25 16 7"] | #include <stdio.h>
void makemas(int n, int x, int y)
{
int i;
int diff;
int mn;
i = 1;
diff = y - x;
mn = (diff > n - 1) ? n - 1 : diff;
while (diff % mn != 0)
mn--;
mn = diff / mn;
while (y - mn > 0 && i++ < n)
y -= mn;
while (n > 0)
{
printf("%d ", y);
y += mn;
n--;
}
}
int main()
{
int t;
int n;
int x;
int y;
scanf("%d", &t);
while (t > 0)
{
scanf("%d%d%d", &n, &x, &y);
makemas(n, x, y);
printf("\n");
t--;
}
} | |
We have a secret array. You don't know this array and you have to restore it. However, you know some facts about this array: The array consists of $$$n$$$ distinct positive (greater than $$$0$$$) integers. The array contains two elements $$$x$$$ and $$$y$$$ (these elements are known for you) such that $$$x < y$$$. If you sort the array in increasing order (such that $$$a_1 < a_2 < \ldots < a_n$$$), differences between all adjacent (consecutive) elements are equal (i.e. $$$a_2 - a_1 = a_3 - a_2 = \ldots = a_n - a_{n-1})$$$. It can be proven that such an array always exists under the constraints given below.Among all possible arrays that satisfy the given conditions, we ask you to restore one which has the minimum possible maximum element. In other words, you have to minimize $$$\max(a_1, a_2, \dots, a_n)$$$.You have to answer $$$t$$$ independent test cases. | For each test case, print the answer: $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the $$$i$$$-th element of the required array. If there are several answers, you can print any (it also means that the order of elements doesn't matter). It can be proven that such an array always exists under the given constraints. | C | ca9d97e731e86cf8223520f39ef5d945 | 4df0cf0664bf7f4150658bedfa116f0f | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"number theory",
"brute force",
"math"
] | 1599230100 | ["5\n2 1 49\n5 20 50\n6 20 50\n5 3 8\n9 13 22"] | null | PASSED | 1,200 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$2 \le n \le 50$$$; $$$1 \le x < y \le 50$$$) — the length of the array and two elements that are present in the array, respectively. | ["1 49 \n20 40 30 50 10\n26 32 20 38 44 50 \n8 23 18 13 3 \n1 10 13 4 19 22 25 16 7"] | #include<stdio.h>
#include<math.h>
#include<stdlib.h>
int main(void) {
int t;
scanf("%d",&t);
for(int i=0;i<t;i++)
{
int n,x,y,d,sf,p,cv,c,sv,s;
scanf("%d%d%d",&n,&x,&y);
d=y-x;
int a[n];
if(n==2)
{
a[0]=x;
a[1]=y;
}
else{
for(int j=1;j<=d;j++)
{
if(d%j==0)
{
p=d/j;
if(p<n)
{
sf=j; break;
}
}
}
cv=y/sf;
if(y%sf!=0){
cv=cv+1;
}
if(cv>=n)
{ s=y;
for(int j=0;j<n;j++)
{
a[j]=s; s=s-sf;
}
}
if(cv<n){
cv=cv-1;
c= cv*sf;
cv=cv+1;
sv=y-c;s=sv;
for(int j=0;j<cv;j++)
{
a[j]=s; s=s+sf;
}
for(int k=cv;k<n;k++)
{
a[k]=s; s=s+sf;
}
}
}
for(int u=0;u<n;u++)
{
printf("%d ",a[u]);
}
printf("\n");
}
return 0;
}
| |
We have a secret array. You don't know this array and you have to restore it. However, you know some facts about this array: The array consists of $$$n$$$ distinct positive (greater than $$$0$$$) integers. The array contains two elements $$$x$$$ and $$$y$$$ (these elements are known for you) such that $$$x < y$$$. If you sort the array in increasing order (such that $$$a_1 < a_2 < \ldots < a_n$$$), differences between all adjacent (consecutive) elements are equal (i.e. $$$a_2 - a_1 = a_3 - a_2 = \ldots = a_n - a_{n-1})$$$. It can be proven that such an array always exists under the constraints given below.Among all possible arrays that satisfy the given conditions, we ask you to restore one which has the minimum possible maximum element. In other words, you have to minimize $$$\max(a_1, a_2, \dots, a_n)$$$.You have to answer $$$t$$$ independent test cases. | For each test case, print the answer: $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the $$$i$$$-th element of the required array. If there are several answers, you can print any (it also means that the order of elements doesn't matter). It can be proven that such an array always exists under the given constraints. | C | ca9d97e731e86cf8223520f39ef5d945 | bd86340a3556d091fdd95d5f6a647c96 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"number theory",
"brute force",
"math"
] | 1599230100 | ["5\n2 1 49\n5 20 50\n6 20 50\n5 3 8\n9 13 22"] | null | PASSED | 1,200 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$2 \le n \le 50$$$; $$$1 \le x < y \le 50$$$) — the length of the array and two elements that are present in the array, respectively. | ["1 49 \n20 40 30 50 10\n26 32 20 38 44 50 \n8 23 18 13 3 \n1 10 13 4 19 22 25 16 7"] | #include<stdio.h>
int main(){
int t;
scanf("%d",&t);
while(t--){
int n,x,y,diff,i,k,minimum_index;
scanf("%d %d %d",&n,&x,&y);
diff=y-x;
for( i=n-1 ; diff%i ; i--) ;
if(y-(n-1)*(diff/i)>0) {
for(int j=0;j<n;j++){
printf("%d",y-j*(diff/i));
if(j==n-1) printf("\n");
else printf(" ");
}
}
else {
for( k=0 ; y-k*(diff/i)>0 ; k++ ) ;
minimum_index=y-(k-1)*(diff/i);
for(int j=0;j<n;j++){
printf("%d",minimum_index+j*(diff/i) );
if(j==n-1) printf("\n");
else printf(" ");
}
}
}
return 0;
}
| |
We have a secret array. You don't know this array and you have to restore it. However, you know some facts about this array: The array consists of $$$n$$$ distinct positive (greater than $$$0$$$) integers. The array contains two elements $$$x$$$ and $$$y$$$ (these elements are known for you) such that $$$x < y$$$. If you sort the array in increasing order (such that $$$a_1 < a_2 < \ldots < a_n$$$), differences between all adjacent (consecutive) elements are equal (i.e. $$$a_2 - a_1 = a_3 - a_2 = \ldots = a_n - a_{n-1})$$$. It can be proven that such an array always exists under the constraints given below.Among all possible arrays that satisfy the given conditions, we ask you to restore one which has the minimum possible maximum element. In other words, you have to minimize $$$\max(a_1, a_2, \dots, a_n)$$$.You have to answer $$$t$$$ independent test cases. | For each test case, print the answer: $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the $$$i$$$-th element of the required array. If there are several answers, you can print any (it also means that the order of elements doesn't matter). It can be proven that such an array always exists under the given constraints. | C | ca9d97e731e86cf8223520f39ef5d945 | 716a12a57062e40b3faab7ac2a356fd8 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"number theory",
"brute force",
"math"
] | 1599230100 | ["5\n2 1 49\n5 20 50\n6 20 50\n5 3 8\n9 13 22"] | null | PASSED | 1,200 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$2 \le n \le 50$$$; $$$1 \le x < y \le 50$$$) — the length of the array and two elements that are present in the array, respectively. | ["1 49 \n20 40 30 50 10\n26 32 20 38 44 50 \n8 23 18 13 3 \n1 10 13 4 19 22 25 16 7"] | #include <stdio.h>
int main()
{
int t = 0;
scanf("%d", &t);
while (t-->0)
{
int n, x, y = 0;
scanf("%d %d %d", &n, &x, &y);
int d = 0;
int k = n - 1;
while (1)
{
if (y - x < k)
--k;
else if ((y - x) % k != 0)
--k;
else
{
d = (y - x) / k;
break;
}
}
int r = n - 1 - k;
for (int i = 0; i <= k; ++i)
{
printf("%d ", x + (i * d));
}
x -= d;
while (r-->0)
{
if (x > 0)
{
printf("%d ", x);
x -= d;
}
else
{
y += d;
printf("%d ", y);
}
}
printf("\n");
}
return 0;
} | |
We have a secret array. You don't know this array and you have to restore it. However, you know some facts about this array: The array consists of $$$n$$$ distinct positive (greater than $$$0$$$) integers. The array contains two elements $$$x$$$ and $$$y$$$ (these elements are known for you) such that $$$x < y$$$. If you sort the array in increasing order (such that $$$a_1 < a_2 < \ldots < a_n$$$), differences between all adjacent (consecutive) elements are equal (i.e. $$$a_2 - a_1 = a_3 - a_2 = \ldots = a_n - a_{n-1})$$$. It can be proven that such an array always exists under the constraints given below.Among all possible arrays that satisfy the given conditions, we ask you to restore one which has the minimum possible maximum element. In other words, you have to minimize $$$\max(a_1, a_2, \dots, a_n)$$$.You have to answer $$$t$$$ independent test cases. | For each test case, print the answer: $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the $$$i$$$-th element of the required array. If there are several answers, you can print any (it also means that the order of elements doesn't matter). It can be proven that such an array always exists under the given constraints. | C | ca9d97e731e86cf8223520f39ef5d945 | bdfc1fd36d0b4b1cc64e0e8203c35695 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"number theory",
"brute force",
"math"
] | 1599230100 | ["5\n2 1 49\n5 20 50\n6 20 50\n5 3 8\n9 13 22"] | null | PASSED | 1,200 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$2 \le n \le 50$$$; $$$1 \le x < y \le 50$$$) — the length of the array and two elements that are present in the array, respectively. | ["1 49 \n20 40 30 50 10\n26 32 20 38 44 50 \n8 23 18 13 3 \n1 10 13 4 19 22 25 16 7"] | #include<stdio.h>
#include<math.h>
#include<string.h>
int main()
{
long long int t,n,cnt=0,i,x,y,ts,df,j,m,k,r;
scanf("%lld",&t);
for(ts=0;ts<t;ts++)
{
scanf("%lld %lld %lld",&n,&x,&y);
df=y-x;
m=x;
r=y;
for(i=1;i<n;i++)
{
if(df%(n-i)==0)
{
k=df/(n-i);
break;
}
}
for(j=0;j<n;j++)
{
if(m<=y)
{
printf("%lld ",m);
m+=k;
}
else
{
x-=k;
if(x<1)
{
r+=k;
printf("%lld ",r);
}
else
printf("%lld ",x);
}
}
printf("\n");
}
return 0;
}
| |
We have a secret array. You don't know this array and you have to restore it. However, you know some facts about this array: The array consists of $$$n$$$ distinct positive (greater than $$$0$$$) integers. The array contains two elements $$$x$$$ and $$$y$$$ (these elements are known for you) such that $$$x < y$$$. If you sort the array in increasing order (such that $$$a_1 < a_2 < \ldots < a_n$$$), differences between all adjacent (consecutive) elements are equal (i.e. $$$a_2 - a_1 = a_3 - a_2 = \ldots = a_n - a_{n-1})$$$. It can be proven that such an array always exists under the constraints given below.Among all possible arrays that satisfy the given conditions, we ask you to restore one which has the minimum possible maximum element. In other words, you have to minimize $$$\max(a_1, a_2, \dots, a_n)$$$.You have to answer $$$t$$$ independent test cases. | For each test case, print the answer: $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the $$$i$$$-th element of the required array. If there are several answers, you can print any (it also means that the order of elements doesn't matter). It can be proven that such an array always exists under the given constraints. | C | ca9d97e731e86cf8223520f39ef5d945 | c0370a859fc7d15edf1384b2b7eb37c9 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"number theory",
"brute force",
"math"
] | 1599230100 | ["5\n2 1 49\n5 20 50\n6 20 50\n5 3 8\n9 13 22"] | null | PASSED | 1,200 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$2 \le n \le 50$$$; $$$1 \le x < y \le 50$$$) — the length of the array and two elements that are present in the array, respectively. | ["1 49 \n20 40 30 50 10\n26 32 20 38 44 50 \n8 23 18 13 3 \n1 10 13 4 19 22 25 16 7"] | #include <stdio.h>
int main()
{
int t, n, x, y;
scanf("%d", &t);
for(int j=0;j<t;j++)
{
scanf("%d %d %d", &n, &x, &y);
int d = y - x;
int diff;
for (int i = 1; i <= d; i++)
{
if (d%i == 0)
{
diff = i;
if (y - (n - 1)*i <= x) break;
}
}
int start = y - (n - 1)*diff;
while (start <= 0)
{
start += diff;
}
for (int i = 0; i<n; i++)
{
printf("%d ", start + (diff*i));
}
printf("\n");
}
}
| |
We have a secret array. You don't know this array and you have to restore it. However, you know some facts about this array: The array consists of $$$n$$$ distinct positive (greater than $$$0$$$) integers. The array contains two elements $$$x$$$ and $$$y$$$ (these elements are known for you) such that $$$x < y$$$. If you sort the array in increasing order (such that $$$a_1 < a_2 < \ldots < a_n$$$), differences between all adjacent (consecutive) elements are equal (i.e. $$$a_2 - a_1 = a_3 - a_2 = \ldots = a_n - a_{n-1})$$$. It can be proven that such an array always exists under the constraints given below.Among all possible arrays that satisfy the given conditions, we ask you to restore one which has the minimum possible maximum element. In other words, you have to minimize $$$\max(a_1, a_2, \dots, a_n)$$$.You have to answer $$$t$$$ independent test cases. | For each test case, print the answer: $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the $$$i$$$-th element of the required array. If there are several answers, you can print any (it also means that the order of elements doesn't matter). It can be proven that such an array always exists under the given constraints. | C | ca9d97e731e86cf8223520f39ef5d945 | b2d4ac43650ac64a6b48063d98d504cb | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"number theory",
"brute force",
"math"
] | 1599230100 | ["5\n2 1 49\n5 20 50\n6 20 50\n5 3 8\n9 13 22"] | null | PASSED | 1,200 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$2 \le n \le 50$$$; $$$1 \le x < y \le 50$$$) — the length of the array and two elements that are present in the array, respectively. | ["1 49 \n20 40 30 50 10\n26 32 20 38 44 50 \n8 23 18 13 3 \n1 10 13 4 19 22 25 16 7"] | #include<stdio.h>
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n,x,y,f=0,g=0,cnt=0,a,b;
scanf("%d%d%d",&n,&x,&y);
for(int i=1;i<=y&&g==0;i++)
{
f=0;
g=0;
for(int j=1;j<=x&&g==0;j++)
{
f=0;
g=0;
cnt=n;
int sum=j;
while(cnt--)
{
if(sum==x)
f=1;
if(sum==y&&f==1)
{
g=1;
a=j;
b=i;
break;
}
sum+=i;
}
}
}
int i=0;
while(n--)
{
printf("%d ",a+(i*b));
i++;
}
printf("\n");
}
return 0;
} | |
We have a secret array. You don't know this array and you have to restore it. However, you know some facts about this array: The array consists of $$$n$$$ distinct positive (greater than $$$0$$$) integers. The array contains two elements $$$x$$$ and $$$y$$$ (these elements are known for you) such that $$$x < y$$$. If you sort the array in increasing order (such that $$$a_1 < a_2 < \ldots < a_n$$$), differences between all adjacent (consecutive) elements are equal (i.e. $$$a_2 - a_1 = a_3 - a_2 = \ldots = a_n - a_{n-1})$$$. It can be proven that such an array always exists under the constraints given below.Among all possible arrays that satisfy the given conditions, we ask you to restore one which has the minimum possible maximum element. In other words, you have to minimize $$$\max(a_1, a_2, \dots, a_n)$$$.You have to answer $$$t$$$ independent test cases. | For each test case, print the answer: $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the $$$i$$$-th element of the required array. If there are several answers, you can print any (it also means that the order of elements doesn't matter). It can be proven that such an array always exists under the given constraints. | C | ca9d97e731e86cf8223520f39ef5d945 | 6d7c2a26294b640756373e43cd91a456 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"number theory",
"brute force",
"math"
] | 1599230100 | ["5\n2 1 49\n5 20 50\n6 20 50\n5 3 8\n9 13 22"] | null | PASSED | 1,200 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$2 \le n \le 50$$$; $$$1 \le x < y \le 50$$$) — the length of the array and two elements that are present in the array, respectively. | ["1 49 \n20 40 30 50 10\n26 32 20 38 44 50 \n8 23 18 13 3 \n1 10 13 4 19 22 25 16 7"] | #include <stdio.h>
int main()
{
int t,n,x,y,i,g,left,noe,j;
scanf("%d",&t);
while(t)
{
scanf("%d %d %d",&n,&x,&y);
g=y-x;
noe=0;
for(i=1;i<=g;i++)
{
if(g%i==0)
{
noe=g/i-1;
if(noe+2<=n)
break;
}
}
left=n-(noe+2);
while(left>0&&x>0)
{
x-=i;
left--;
}
while(x<=0)
x+=i;
for(j=1;j<=n;j++)
{
printf("%d ",x);
x+=i;
}
printf("\n");
t--;
}
} | |
We have a secret array. You don't know this array and you have to restore it. However, you know some facts about this array: The array consists of $$$n$$$ distinct positive (greater than $$$0$$$) integers. The array contains two elements $$$x$$$ and $$$y$$$ (these elements are known for you) such that $$$x < y$$$. If you sort the array in increasing order (such that $$$a_1 < a_2 < \ldots < a_n$$$), differences between all adjacent (consecutive) elements are equal (i.e. $$$a_2 - a_1 = a_3 - a_2 = \ldots = a_n - a_{n-1})$$$. It can be proven that such an array always exists under the constraints given below.Among all possible arrays that satisfy the given conditions, we ask you to restore one which has the minimum possible maximum element. In other words, you have to minimize $$$\max(a_1, a_2, \dots, a_n)$$$.You have to answer $$$t$$$ independent test cases. | For each test case, print the answer: $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the $$$i$$$-th element of the required array. If there are several answers, you can print any (it also means that the order of elements doesn't matter). It can be proven that such an array always exists under the given constraints. | C | ca9d97e731e86cf8223520f39ef5d945 | 47d12c103fbad2d21521a3ecbaffb6e0 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"number theory",
"brute force",
"math"
] | 1599230100 | ["5\n2 1 49\n5 20 50\n6 20 50\n5 3 8\n9 13 22"] | null | PASSED | 1,200 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$2 \le n \le 50$$$; $$$1 \le x < y \le 50$$$) — the length of the array and two elements that are present in the array, respectively. | ["1 49 \n20 40 30 50 10\n26 32 20 38 44 50 \n8 23 18 13 3 \n1 10 13 4 19 22 25 16 7"] | #include <stdio.h>
#include <stdlib.h>
typedef long long ll;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define min(l,r) ((l)<(r)?l:r)
#define max(l,r) ((l)>(r)?l:r)
#define swap(l,r) {ll tp=l;l=r;r=tp;}
int upcmpll(const void *a, const void *b){return(*(ll*)a==*(ll*)b?0:(*(ll*)a>*(ll*)b?1:-1));}
void sort_u(ll*a, ll n){qsort(a,n,sizeof(ll),upcmpll);}
ll a[100];
ll x,y,n;
int t;
void solve(){
ll ans = 0;
ll tmp = n-1;
while((y-x)%tmp > 0 && tmp > 1) tmp--;
int idx = 0;
ll td = (y-x)/tmp;
ll tn = tmp+1;
rep(i,tn){
a[idx++] = x+td*i;
}
if(n-idx>0){
ll tv = x;
while(n-idx > 0 && (tv - td > 0)) {
tv -= td;
a[idx++] = tv;
}
tv = y;
while(n-idx > 0) {
tv += td;
a[idx++] = tv;
}
}
}
//for q-testcase
int main(){
scanf("%d", &t);
rep(tes,t){
scanf("%lld%lld%lld", &n,&x,&y);
solve();
rep(i,n) printf("%lld ", a[i]);
puts("");
//if(solve()){ puts("YES"); }else puts("NO");
}
}
| |
We have a secret array. You don't know this array and you have to restore it. However, you know some facts about this array: The array consists of $$$n$$$ distinct positive (greater than $$$0$$$) integers. The array contains two elements $$$x$$$ and $$$y$$$ (these elements are known for you) such that $$$x < y$$$. If you sort the array in increasing order (such that $$$a_1 < a_2 < \ldots < a_n$$$), differences between all adjacent (consecutive) elements are equal (i.e. $$$a_2 - a_1 = a_3 - a_2 = \ldots = a_n - a_{n-1})$$$. It can be proven that such an array always exists under the constraints given below.Among all possible arrays that satisfy the given conditions, we ask you to restore one which has the minimum possible maximum element. In other words, you have to minimize $$$\max(a_1, a_2, \dots, a_n)$$$.You have to answer $$$t$$$ independent test cases. | For each test case, print the answer: $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the $$$i$$$-th element of the required array. If there are several answers, you can print any (it also means that the order of elements doesn't matter). It can be proven that such an array always exists under the given constraints. | C | ca9d97e731e86cf8223520f39ef5d945 | 103f3cf471228d62047ee677b4ea93ef | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"number theory",
"brute force",
"math"
] | 1599230100 | ["5\n2 1 49\n5 20 50\n6 20 50\n5 3 8\n9 13 22"] | null | PASSED | 1,200 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$2 \le n \le 50$$$; $$$1 \le x < y \le 50$$$) — the length of the array and two elements that are present in the array, respectively. | ["1 49 \n20 40 30 50 10\n26 32 20 38 44 50 \n8 23 18 13 3 \n1 10 13 4 19 22 25 16 7"] | #include <stdio.h>
#define ll long long
int main()
{
int t;
scanf("%d", &t);
while (t--)
{
int n, x, y;
scanf("%d%d%d", &n, &x, &y);
int jiange = 1;
int zhongjiangeshu = y - x - 1;
while (1)
{
if ((zhongjiangeshu + 1) % jiange == 0)
{
if (zhongjiangeshu / jiange + 2 <= n)
{
break;
}
}
jiange++;
}
int tempy = y;
while (1)
{
printf("%d ", tempy);
tempy -= jiange;
n--;
if (tempy <= 0 || n == 0)
break;
}
tempy = y + jiange;
while (n--)
{
printf("%d ", tempy);
tempy += jiange;
}
printf("\n");
}
return 0;
}
| |
We have a secret array. You don't know this array and you have to restore it. However, you know some facts about this array: The array consists of $$$n$$$ distinct positive (greater than $$$0$$$) integers. The array contains two elements $$$x$$$ and $$$y$$$ (these elements are known for you) such that $$$x < y$$$. If you sort the array in increasing order (such that $$$a_1 < a_2 < \ldots < a_n$$$), differences between all adjacent (consecutive) elements are equal (i.e. $$$a_2 - a_1 = a_3 - a_2 = \ldots = a_n - a_{n-1})$$$. It can be proven that such an array always exists under the constraints given below.Among all possible arrays that satisfy the given conditions, we ask you to restore one which has the minimum possible maximum element. In other words, you have to minimize $$$\max(a_1, a_2, \dots, a_n)$$$.You have to answer $$$t$$$ independent test cases. | For each test case, print the answer: $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the $$$i$$$-th element of the required array. If there are several answers, you can print any (it also means that the order of elements doesn't matter). It can be proven that such an array always exists under the given constraints. | C | ca9d97e731e86cf8223520f39ef5d945 | 107f9081dcf5a74931b68866d408975e | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"number theory",
"brute force",
"math"
] | 1599230100 | ["5\n2 1 49\n5 20 50\n6 20 50\n5 3 8\n9 13 22"] | null | PASSED | 1,200 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$2 \le n \le 50$$$; $$$1 \le x < y \le 50$$$) — the length of the array and two elements that are present in the array, respectively. | ["1 49 \n20 40 30 50 10\n26 32 20 38 44 50 \n8 23 18 13 3 \n1 10 13 4 19 22 25 16 7"] | #include<stdio.h>
#include<math.h>
#include<string.h>
int main()
{
long long int t,n,cnt=0,i,x,y,ts,df,j,m,k,r;
scanf("%lld",&t);
for(ts=0;ts<t;ts++)
{
scanf("%lld %lld %lld",&n,&x,&y);
df=y-x;
m=x;
r=y;
for(i=1;i<n;i++)
{
if(df%(n-i)==0)
{
k=df/(n-i);
break;
}
}
for(j=0;j<n;j++)
{
if(m<=y)
{
printf("%lld ",m);
m+=k;
}
else
{
x-=k;
if(x<1)
{
r+=k;
printf("%lld ",r);
}
else
printf("%lld ",x);
}
}
printf("\n");
}
return 0;
}
| |
We have a secret array. You don't know this array and you have to restore it. However, you know some facts about this array: The array consists of $$$n$$$ distinct positive (greater than $$$0$$$) integers. The array contains two elements $$$x$$$ and $$$y$$$ (these elements are known for you) such that $$$x < y$$$. If you sort the array in increasing order (such that $$$a_1 < a_2 < \ldots < a_n$$$), differences between all adjacent (consecutive) elements are equal (i.e. $$$a_2 - a_1 = a_3 - a_2 = \ldots = a_n - a_{n-1})$$$. It can be proven that such an array always exists under the constraints given below.Among all possible arrays that satisfy the given conditions, we ask you to restore one which has the minimum possible maximum element. In other words, you have to minimize $$$\max(a_1, a_2, \dots, a_n)$$$.You have to answer $$$t$$$ independent test cases. | For each test case, print the answer: $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the $$$i$$$-th element of the required array. If there are several answers, you can print any (it also means that the order of elements doesn't matter). It can be proven that such an array always exists under the given constraints. | C | ca9d97e731e86cf8223520f39ef5d945 | ff2d12891fd12d39a1d811cc65f55411 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"number theory",
"brute force",
"math"
] | 1599230100 | ["5\n2 1 49\n5 20 50\n6 20 50\n5 3 8\n9 13 22"] | null | PASSED | 1,200 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$2 \le n \le 50$$$; $$$1 \le x < y \le 50$$$) — the length of the array and two elements that are present in the array, respectively. | ["1 49 \n20 40 30 50 10\n26 32 20 38 44 50 \n8 23 18 13 3 \n1 10 13 4 19 22 25 16 7"] | #include <stdio.h>
int main(int argc, char const *argv[])
{
int test;
scanf("%d", &test);
for (int i = 0; i < test; i++)
{
int n, x, y, d;
scanf("%d %d %d", &n, &x, &y);
int ans = (y - x);
for (int i = (n - 1); i >= 1; i--)
{
if (!(ans % i))
{
d = (ans / i);
break;
}
}
int ctr = 0;
for (int i = (x); (ctr < n) && (i <= y); i += d, ctr++)
{
printf("%d ", i);
}
if (ctr < n)
{
for (int i = (x - d); (ctr < n) && (i > 0); i -= d, ctr++)
{
printf("%d ", i);
}
}
if (ctr < n)
{
for (int i = (y+d); ctr < n; i += d, ctr++)
{
printf("%d ", i);
}
}
printf("\n");
}
return 0;
}
| |
We have a secret array. You don't know this array and you have to restore it. However, you know some facts about this array: The array consists of $$$n$$$ distinct positive (greater than $$$0$$$) integers. The array contains two elements $$$x$$$ and $$$y$$$ (these elements are known for you) such that $$$x < y$$$. If you sort the array in increasing order (such that $$$a_1 < a_2 < \ldots < a_n$$$), differences between all adjacent (consecutive) elements are equal (i.e. $$$a_2 - a_1 = a_3 - a_2 = \ldots = a_n - a_{n-1})$$$. It can be proven that such an array always exists under the constraints given below.Among all possible arrays that satisfy the given conditions, we ask you to restore one which has the minimum possible maximum element. In other words, you have to minimize $$$\max(a_1, a_2, \dots, a_n)$$$.You have to answer $$$t$$$ independent test cases. | For each test case, print the answer: $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the $$$i$$$-th element of the required array. If there are several answers, you can print any (it also means that the order of elements doesn't matter). It can be proven that such an array always exists under the given constraints. | C | ca9d97e731e86cf8223520f39ef5d945 | e283d74d41a72876922bc44fe3317c6b | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"number theory",
"brute force",
"math"
] | 1599230100 | ["5\n2 1 49\n5 20 50\n6 20 50\n5 3 8\n9 13 22"] | null | PASSED | 1,200 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$2 \le n \le 50$$$; $$$1 \le x < y \le 50$$$) — the length of the array and two elements that are present in the array, respectively. | ["1 49 \n20 40 30 50 10\n26 32 20 38 44 50 \n8 23 18 13 3 \n1 10 13 4 19 22 25 16 7"] | #include<stdio.h>
int main(){
int t; scanf("%d",&t);
while(t--){
int n,x,y; scanf("%d %d %d",&n,&x,&y);
int dif=y-x; int k=n-1;
while(dif%k!=0){
k--;
}
int d=dif/k;
int l=dif/d+1,min=x,max=y;
while(l<n){
if(min-d>0){min=min-d; l++;}
else{max=max+d; l++;}
}
for(int i=0;i<n;i++){printf("%d ",min+d*i);} printf("\n");
}
}
| |
We have a secret array. You don't know this array and you have to restore it. However, you know some facts about this array: The array consists of $$$n$$$ distinct positive (greater than $$$0$$$) integers. The array contains two elements $$$x$$$ and $$$y$$$ (these elements are known for you) such that $$$x < y$$$. If you sort the array in increasing order (such that $$$a_1 < a_2 < \ldots < a_n$$$), differences between all adjacent (consecutive) elements are equal (i.e. $$$a_2 - a_1 = a_3 - a_2 = \ldots = a_n - a_{n-1})$$$. It can be proven that such an array always exists under the constraints given below.Among all possible arrays that satisfy the given conditions, we ask you to restore one which has the minimum possible maximum element. In other words, you have to minimize $$$\max(a_1, a_2, \dots, a_n)$$$.You have to answer $$$t$$$ independent test cases. | For each test case, print the answer: $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the $$$i$$$-th element of the required array. If there are several answers, you can print any (it also means that the order of elements doesn't matter). It can be proven that such an array always exists under the given constraints. | C | ca9d97e731e86cf8223520f39ef5d945 | 7ffb13432c008ef8837ccfe6703f3076 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"number theory",
"brute force",
"math"
] | 1599230100 | ["5\n2 1 49\n5 20 50\n6 20 50\n5 3 8\n9 13 22"] | null | PASSED | 1,200 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$2 \le n \le 50$$$; $$$1 \le x < y \le 50$$$) — the length of the array and two elements that are present in the array, respectively. | ["1 49 \n20 40 30 50 10\n26 32 20 38 44 50 \n8 23 18 13 3 \n1 10 13 4 19 22 25 16 7"] | #include<stdio.h>
int main()
{int t;
scanf("%d\n",&t);
while(t--){
int n,x,y,d,i=1,r,diff,max=3000;
int x1,y1,main_diff;
scanf("%d%d%d\n",&n,&x,&y);
d=y-x;x1=x;y1=y;
while(n>=i+1)
{ if((d/i)*i==d)
{ x=x1;y=y1;diff=d/i;
r=n-2-(i-1);
while(x-diff>0&&r>0)
{x=x-diff;r--;}
if(r>0)
y=y+diff*r;
if(y<=max){
max=y;main_diff=diff;}
}
i++;
}
for(int j=0;j<n;j++)
{printf("%d ",max-diff*j);}
printf("\n");
}
return 0;
}
| |
We have a secret array. You don't know this array and you have to restore it. However, you know some facts about this array: The array consists of $$$n$$$ distinct positive (greater than $$$0$$$) integers. The array contains two elements $$$x$$$ and $$$y$$$ (these elements are known for you) such that $$$x < y$$$. If you sort the array in increasing order (such that $$$a_1 < a_2 < \ldots < a_n$$$), differences between all adjacent (consecutive) elements are equal (i.e. $$$a_2 - a_1 = a_3 - a_2 = \ldots = a_n - a_{n-1})$$$. It can be proven that such an array always exists under the constraints given below.Among all possible arrays that satisfy the given conditions, we ask you to restore one which has the minimum possible maximum element. In other words, you have to minimize $$$\max(a_1, a_2, \dots, a_n)$$$.You have to answer $$$t$$$ independent test cases. | For each test case, print the answer: $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the $$$i$$$-th element of the required array. If there are several answers, you can print any (it also means that the order of elements doesn't matter). It can be proven that such an array always exists under the given constraints. | C | ca9d97e731e86cf8223520f39ef5d945 | 3096599b0e56e5e47ba1d70c02e52d45 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"number theory",
"brute force",
"math"
] | 1599230100 | ["5\n2 1 49\n5 20 50\n6 20 50\n5 3 8\n9 13 22"] | null | PASSED | 1,200 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$2 \le n \le 50$$$; $$$1 \le x < y \le 50$$$) — the length of the array and two elements that are present in the array, respectively. | ["1 49 \n20 40 30 50 10\n26 32 20 38 44 50 \n8 23 18 13 3 \n1 10 13 4 19 22 25 16 7"] | #include <stdio.h>
int step(int n, int delta){
if( n == 2 ){
return delta;
}
int i, m = 0;
for( i = 1; i <= 50; i++ ){
if( delta%i == 0 ){
m = i;
if( delta/i <= n-1 ){
break;
}
}
}
return m;
}
int main(){
int T;
int n, x, y;
int m, z, d;
int i;
scanf("%d", &T);
while( T-- ){
scanf("%d %d %d", &n, &x, &y);
m = step(n, y-x);
d = 1+((y-1)%m);
z = m*(n-1) + d;
if( z >= y ){
for( i = d; i <= z; i+=m ){
if( i > d ) printf(" ");
printf("%d", i);
}
}else{
z = 0;
for( i = y; i >= 1 && z < n; i-=m, z++ ){
if( i < y ) printf(" ");
printf("%d", i);
}
}
printf("\n");
}
return 0;
} | |
We have a secret array. You don't know this array and you have to restore it. However, you know some facts about this array: The array consists of $$$n$$$ distinct positive (greater than $$$0$$$) integers. The array contains two elements $$$x$$$ and $$$y$$$ (these elements are known for you) such that $$$x < y$$$. If you sort the array in increasing order (such that $$$a_1 < a_2 < \ldots < a_n$$$), differences between all adjacent (consecutive) elements are equal (i.e. $$$a_2 - a_1 = a_3 - a_2 = \ldots = a_n - a_{n-1})$$$. It can be proven that such an array always exists under the constraints given below.Among all possible arrays that satisfy the given conditions, we ask you to restore one which has the minimum possible maximum element. In other words, you have to minimize $$$\max(a_1, a_2, \dots, a_n)$$$.You have to answer $$$t$$$ independent test cases. | For each test case, print the answer: $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the $$$i$$$-th element of the required array. If there are several answers, you can print any (it also means that the order of elements doesn't matter). It can be proven that such an array always exists under the given constraints. | C | ca9d97e731e86cf8223520f39ef5d945 | 04366d929bbe629b895ba5e4d285032c | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"number theory",
"brute force",
"math"
] | 1599230100 | ["5\n2 1 49\n5 20 50\n6 20 50\n5 3 8\n9 13 22"] | null | PASSED | 1,200 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$2 \le n \le 50$$$; $$$1 \le x < y \le 50$$$) — the length of the array and two elements that are present in the array, respectively. | ["1 49 \n20 40 30 50 10\n26 32 20 38 44 50 \n8 23 18 13 3 \n1 10 13 4 19 22 25 16 7"] | #include<stdio.h>
int main(){long int t,i,n,x,y,j,c,k,h,y1;
scanf("%ld",&t);
for(i=0;i<t;i++)
{
scanf("%ld%ld%ld",&n,&x,&y);
c=0;
for(j=n-1;j>=1;j--)
{
if((y-x)%j==0)
{
c++;
break;
}
}
if(c==0)
{
k=0;
h=y-x;
y1=y;
while(y>0&&k<n)
{
printf("%ld ",y);
y=y-h;
k++;
}
for(j=0;j<n-k;j++)
{
printf("%ld ",y1+h);
y1=y1+h;
}
printf("\n");
}
else
{
k=0;
h=(y-x)/j;
y1=y;
while(y>0&&k<n)
{
printf("%ld ",y);
y=y-h;
k++;
}
for(j=0;j<n-k;j++)
{
printf("%ld ",y1+h);
y1=y1+h;
}
printf("\n");
}
}
return 0;
}
| |
We have a secret array. You don't know this array and you have to restore it. However, you know some facts about this array: The array consists of $$$n$$$ distinct positive (greater than $$$0$$$) integers. The array contains two elements $$$x$$$ and $$$y$$$ (these elements are known for you) such that $$$x < y$$$. If you sort the array in increasing order (such that $$$a_1 < a_2 < \ldots < a_n$$$), differences between all adjacent (consecutive) elements are equal (i.e. $$$a_2 - a_1 = a_3 - a_2 = \ldots = a_n - a_{n-1})$$$. It can be proven that such an array always exists under the constraints given below.Among all possible arrays that satisfy the given conditions, we ask you to restore one which has the minimum possible maximum element. In other words, you have to minimize $$$\max(a_1, a_2, \dots, a_n)$$$.You have to answer $$$t$$$ independent test cases. | For each test case, print the answer: $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the $$$i$$$-th element of the required array. If there are several answers, you can print any (it also means that the order of elements doesn't matter). It can be proven that such an array always exists under the given constraints. | C | ca9d97e731e86cf8223520f39ef5d945 | fda7a64e50d79d6d5c95b750998c2991 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"number theory",
"brute force",
"math"
] | 1599230100 | ["5\n2 1 49\n5 20 50\n6 20 50\n5 3 8\n9 13 22"] | null | PASSED | 1,200 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$2 \le n \le 50$$$; $$$1 \le x < y \le 50$$$) — the length of the array and two elements that are present in the array, respectively. | ["1 49 \n20 40 30 50 10\n26 32 20 38 44 50 \n8 23 18 13 3 \n1 10 13 4 19 22 25 16 7"] | #include <stdio.h>
int main()
{
//int a;scanf("%d",&a);printf("%d\n",a);
//printf("1\n");return(0);
int t,i;scanf("%d",&t);
for(i=0;i<t;i++)
{
int n,x,y,j,d,k=1;scanf("%d %d %d",&n,&x,&y);//printf("%d %d %d\n",n,x,y);
for(j=y;j<=3000;j++)
{
int u=0;d=1;
while(d!=52)
{
if((j-(d*(n-1))>0)&&(j-(d*(n-1))<=x)&&(((j-(d*(n-1))-x)%d)==0)&&(((j-y)%d)==0))
{
u++;int l=0;
while(l!=n)
{
printf("%d ",j-(l*d));l++;
}
printf("\n");
}
if(u==1)break;
d++;
}
if(u==1)
break;
}
}
return 0;
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.