MAKEDIV3 - Editorial

bro just guess the value of 10^100…u are going to get your answer…i have done the same mistake as u r doing in the contest …:joy::joy::joy:

i know bro :joy:, but it was the condition so that’s why and i didn’t know what else to do

Hello , Can anyone please tell me where my code is wrong ?
Thanks !

#include <stdio.h>
#include <math.h>
int main()
{
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++)
{
int d;
scanf("%d", &d);
for (int j = pow(10,d - 1); j < pow(10,d); j++)
{
if (j % 2 != 0 && j % 3 == 0 && j % 9 != 0)
{
printf("%d\n", j);
break;
}
}
}

return 0;

}

looking in constraints given in problem that is no of digit can be upto 10000 so it means number can be as big as 10^10000 so its is impossible to store our answers in data type like int as it can merely store 9 or digits,so try the approach given in editorial as it seems the only way possible.

#include<bits/stdc++.h>
using namespace std;
int main()
{
int tc;cin>>tc;
while(tc–)
{
int n;cin>>n;
if(n==1)
{
for(int i=1;i<10;i=i+2)
{
if(((i%3)==0) and ((i%9)!=0))
{cout<<i<<"\n";break;}

                             }
                            }
                            else{
                                               
                               int i=pow(10,n-1)+1;
                               int j=pow(10,n);
                               for(;i<j;i=i+2)
                               {
                                               if(((i%3)==0)  and ((i%9)!=0))
                               {cout<<i<<"\n";break;}
                               }
                            
                            }
            }

}

can anyone tell what im missing it is giving me wrong answer…!!!
i think power func cannot handle upto 10^5 ,so whether i do this with binary exponentiation???or something other is wrong??

Can anyone let me know why the given output for the third input (‘3’) is given as 123? Isn’t it ‘105’? Cause, 105 is both odd and divisible by 3 but not 9, hence satisfying the condition.

My method is very simple :-

for _ in range(int(input())):
	n=int(input())
	if n==1: print(3)
	else: print(10**(n-1)+11) # I can even add 11 if n >= 2 if condition is not about the least one.
		# print(10**(n-1)+5)  # condition satisfied! Returns the least number

Here both 5, 11 … etc. are applicable since in the statement it’s nowhere mentioned that we need to return the least number in that range which is divisible by 3 but not by 9!

why i am getting wa in this solution please help

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int t;
    cin>>t;
    while(t--){
    int n;
    cin>>n;
    int num =pow(10,n-1);
     
    while(num/pow(10,n-1)<10){
        if(num%3==0 && num%9!=0){
            if(num%2!=0){
            cout<<num<<endl;
            break;
            }
        }
        num = num+1;
    }
    }
    return 0;
}

n can be upto 10^4, in worst case pow (10, n - 1) could be 10^{10^4}. Which cannot be stored in num and neither can be calculated by pow.

# cook your dish here
t=int(input())
while(t):
    n=int(input())
    if n==1:
        print(3)
    else:
        start=10**(n-1)+1
        end=(10**n)-1
        ans=start
        while start<=end:
            if ans%9!=0 and ans%3==0:
                print(ans)
                break
            start+=2
            ans+=2
    t-=1

can anyone explain why my code throw error “runtime error”

#include <stdio.h>

int main(void) {
	int t;
	scanf("%d", &t);
	while(t--){
	    long long int a,b, c, d;
	    scanf("%lld\n", &a);
	    b =a;
	    c =1;
	    if(a == 1){
	        printf("3\n");
	    }
	    else{
	        while(b > 1){
	            c*=10;
	            b--;
	        }
	        d = c-1+3;
	        if (d%3 != 0){
	        printf("%lld\n", c+2);
	        }
	        else{
	            printf("%lld\n", c+5);
	            }
	        }
	}
	return 0;
}

This is my code, it fails in a hidden test case,
1
20
your output
-8446744073709551611

why does a negative answer comes even using lld?? I get that computers when performing greater calculations, struggle but can anyone help me with that? or is there a problem with my approach.

Thank you