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;
}
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;
}
}
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;
}