#include<bits/stdc++.h>
using namespace std;
#define ll long long
//#define int ll
#define rep(n) rep1(i,n)
#define rep1(i,n) rep2(i,0,n)
#define rep2(i,a,b) for(int i=a; i<(b); ++i)
#define rep3(i,a,b) for(int i=a; i>=(b); --i)
#define pb push_back
#define pii pair<int,int>
#define sz(a) ((int)a.size())
#define all(a) a.begin(),a.end()
#define pow2(x) (1ll<<(x))
#define inf 0x3f3f3f3f
#ifdef i_am_noob
#define bug(...) cerr << "#" << __LINE__ << " " << #__VA_ARGS__ << "- ", _do(__VA_ARGS__)
template<typename T> void _do(T x){cerr << x << endl;}
template<typename T, typename ...S> void _do(T x, S... y){cerr << x << ", ";_do(y...);}
#else
#define bug(...) 49
#endif
const int maxn=2005,mod=1000000007;
int t,n,cnt,minn,minid;
signed main(){
ios_base::sync_with_stdio(0),cin.tie(0);
cin >> t;
while(t--){
cin >> n;
n+=2;
cnt=0;
minn=inf;
rep2(i,1,n) if(__gcd(i,n)==1){
cnt++;
if(2*i>n) continue;
int a=i,b=n-i,x=0;
while(a>1&&b>1){
if(a>b){
x+=a/b;
a%=b;
}
else{
x+=b/a;
b%=a;
}
if(x>=minn) break;
}
if(a>b) x+=a-1;
if(b>a) x+=b-1;
if(x<minn) minn=x,minid=i;
}
cout << cnt << "\n";
vector<int> vec;
int a=minid,b=n-minid;
while(a>1&&b>1){
if(a>b){
rep(a/b) vec.pb(1);
a%=b;
}
else{
rep(b/a) vec.pb(0);
b%=a;
}
}
if(a>b) rep(a-1) vec.pb(1);
if(b>a) rep(b-1) vec.pb(0);
for(auto i: vec) cout << i << ' ';
cout << "\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
117 ms |
328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
39 ms |
304 KB |
Output is correct |
2 |
Correct |
87 ms |
204 KB |
Output is correct |
3 |
Correct |
82 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
894 ms |
296 KB |
Output is correct |
2 |
Execution timed out |
1056 ms |
292 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |