MAKEDIV3 - Editorial

in the question it is given, 1≤N≤10^4.
now in your code take N=30, you will get garbage value

	int n;
	cin >> n;
	if(n % 3 == 0) {
		cout << string(n,'1') << endl;
	}
	else cout << string(n,'3') << endl;

Why isn’t this code valid?

It fails for the N=9 case (your solution gives a number that is divisible by 9).

1 Like

Can anyone say what is wrong with this program
#include <stdio.h>
#include <math.h>

int main(void) {
// your code goes here
int i,t;
scanf("%d",&t);
for(i=1;i<=t;i++)
{
long int n,j;
scanf("%ld",&n);
for(j=pow(10,(n-1));j<=(pow(10,n))-1;j++)
{
if(j%2!=0 && j%3==0 && j%9!=0)
{
printf("%ld\n",j);
break;
}
}
}
return 0;
}

#include
#include
using namespace std;

int main()
{
int T,n;
cin >> T;

while (T--)
{
    cin >> n;
    if (n == 1)
    {
        cout<<3<<endl;
    }
    else
    {
        cout<< pow(10, n - 1) + 5<<endl;
    }
    
}
return 0;

}
why this getting WA
logic is
if n =1 then print 3
otherwise print in following format
n=2 , 15
n=3, 105 ,
n=4 ,1005,
n=5 ,10005 and so on.

hi so this was my solution for the question,but it was not accepted can someone tell me what is wrong with this code?
#include <stdio.h>
#include <math.h>
int main(void) {
// your code goes here
int t;
scanf("%d\n",&t);
while(t–)
{
int n,a,b;
scanf("%d\n",&n);
a=pow(10,(n-1));
b=pow(10,n);
int i=a;
//printf("%d %d\n",a,b);
for(i>=a;i<b;i++)
{
if(i%2!=0 && i%3==0 && i%9!=0)
{
printf("%d\n",i);
break;
}

    }
}

return 0;

}

int range from -2,147,483,648 to 2,147,483,647

as n can be 1000 also means it will overflow

check this data type

try running for
2
5
21

you will get:
10005
-2147483643

I think this is due to space constraints

What is wrong with this
https://www.codechef.com/viewsolution/51417990

It doesn’t appear to give any output for N\ge6.

#include
using namespace std;

int main() {
int n;
cin>>n;
while(n–)
{
int t;
cin>>t;
int x=1;
t–;
while(t–)
{
x=x*10;
}
while(true)
{
if(x%2!=0 && x%9>=1 && x%3==0)
{
break;
}
x++;
}
cout<<x<<endl;
}

return 0;

}

Can someone tell me why 105 is not a valid answer for n=3.?

  int i;
    int n;
    cin>>n;
    int start=pow(10,n-1);
    int end=pow(10,n);

    for (i = start+2; i < end; i+=3)       
    {
        if(i%2!=0 and i%3==0 and i%9!=0){
            cout<<i<<endl;
            break;
        }
    }

and why this code is wrong?

Did you try for inputs where N \ge 20 ?

1 Like

i only did this.
pow(10,n)-7 :slightly_smiling_face:

But Why ?

You’ve got a 100% reproducible testcase - get debugging!

HELLO, can someone tell me why this code is giving WA -
#include
#include
int main(int argc, char const *argv[]) {
int t,n,num={0};

std::cin >> t;
while (t–) {
std::cin >> n;
num= pow(10,n-1)+2;
while (num%2==0 || num%9==0) {
num+=3;
}
std::cout << num<< ‘\n’;
num=0;
}
return 0;
}

Can someone please tell me why is my code wrong? My approach is to print 1 in the beginning and 5 in the end, and n-2 zeroes in between.

#include <bits/stdc++.h>

#define for0(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define forc(i, l, r) for (int i = (int)(l); i <= (int)(r); ++i)
#define forr0(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define forr1(i, n) for (int i = (int)(n); i >= 1; --i)

using namespace std;

#define pb push_back
#define pob pop_back
#define fi first
#define se second

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef double ld;



int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;
    int t;
    cin>>t;
    while(t--) {
        int n;
        cin>>n;
        if(n==1) cout<<"3"<<endl;
        else {
            int ans=pow(10,(n-1))+5;
            cout<<ans<<endl;
        }
        
    }
    return 0;
}

You should have at least gone through previous comments.
Anyways, here’s a test case for you.

1
50
1 Like

why this code is wrong?