Make it Divisible: MAKEDIV3

                     

link: https://codechef.com/CU1PP0007/problems/MAKEDIV3

Contributor: Priya (CSE)

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.

Solution:

#include<bits/stdc++.h>
#define ll long long int 
using namespace std;

int main()
{
    ll t,num;
    cin>>t;
    while(t--)
    {
        cin>>num;
        if(num==1){
            cout<<3<<endl;
            continue;
        }
        for(ll i=1;i<=num;i++)
        {
        if(i == 1 )
        {
            cout<<1;
        }
        else if(i == num )
        {
            cout<<5;
        }
        else{
            cout<<0;
        }
        
        }
        cout<<endl;
    }
    
}

* The material and content uploaded on this website are for general information and reference purposes only. Please do it by your own first.