-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSubsegment Divisibility.cpp
More file actions
72 lines (63 loc) · 1.17 KB
/
Subsegment Divisibility.cpp
File metadata and controls
72 lines (63 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define lld double
int M=1e9+7;
const int array_size = 1e6+100;
bool primes[array_size];
void sieve(){
primes[0] = false;
primes[1] = false;
for(ll i = 2;i*i<=array_size;i++){
if(primes[i]){
for(ll j=i*i;j<=array_size;j+=i)
primes[j] = false;
}
}
}
const int size = 501;
int val[size];
int pre[size];
void preCal(){
//cout<<"nsd\n";
val[0]=1;
pre[1]=1;
int cur=2;
for(int i=1;i<500;i++){
while(1){
bool found = false;
for(int j=i-1;j>=0;j--){
if((cur+(pre[i]-pre[j]))%(i+1-j)==0){
found = true;
break;
}
}
if(!found)break;
else cur++;
}
pre[i+1]=pre[i]+cur;
val[i]=cur;
cur++;
}
}
void solve(){
int n;
cin>>n;
for(int i=0;i<n;i++)
cout<<val[i]<<" ";
cout<<"\n";
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
//memset(primes,true,sizeof(primes));
//sieve();
//memset(dp,false,sizeof(dp));
preCal();
int t;
cin>>t;
while(t--)
solve();
return 0;
}