Given an integer N, help Chef in finding an N-digit odd positive integer X such that X is divisible by 3 but not by 9.
Note: There should not be any leading zeroes in X. In other words, 003 is not a valid 3-digit odd positive integer.
Input Format
- The first line of input contains a single integer T, denoting the number of testcases. The description of the T testcases follows.
- The first and only line of each test case contains a single integer N, denoting the number of digits in X.
Output Format
For each testcase, output a single line containing an N-digit odd positive integer X in decimal number system, such that X is divisible by 3 but not by 9.
Sample Input 1
Sample Output 1
Solution:
#include<bits/stdc++.h>
using namespace std;
void solve(){
long int n;
cin>>n;
vector<int> var(n, 3);
if(n%3 == 0){
var[n-1] = 1;
var[n-2] = 2;
}
for (int i = 0; i < n; i++)
{
cout<<var[i];
}
cout<<endl;
}
int main(){
int t;
cin>>t;
while (t--)
{
solve();
}
return 0;
}
0 Comments