Ad Code

Responsive Advertisement

Make it Divisible || Problem Code: MAKEDIV3 || codechef starters 12



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

3
1
2
3

Sample Output 1

3
15
123

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;

}

Post a Comment

0 Comments

Close Menu