ITGUY34 - Editorial

Problem: Contest Page | CodeChef

DIFFICULTY:

EASY.

PROBLEM:

Chef has a number N, Cheffina challenges the chef to check the divisibility of all the permutation of N by 3. If any of the permutations is divisible by 3 then print 1 else print 0.

Program:

#include<bits/stdc++.h>
using namespace std;
int main()
 {
	ios_base::sync_with_stdio(false);
   	cin.tie(NULL);
   	cout.tie(NULL);
   	int n,t;
	cin>>t;
	for(int i=1;i<=t;i++)
	{
		int n;
		cin>>n;
		if(n%3==0)cout<<1<<"\n";
		else cout<<0<<"\n";
	}

}

@references are you sure about this answer???

2 Likes

Yes, 100% sure.
Because sum of digits are same for all the permutations this is divisibility test of 3.
Thats why all permutations are divisible.
Else not divisible.

1 Like

Coffee

no … you are correct … i’m sorry!!!

1 Like

XD XD… you should refrain from insulting others if you don’t understand the solution yourself :rofl:

1 Like

yes yes … !! i have understood … i guess i wasn’t thinking right!

1 Like

@references you changed the code !!!
that’s not fair you are the problem setter and you are changing your code in the tutorial.

1 Like

he just added the input stuff what’s the issue in that ?

2 Likes

Actually in hurry I did some mistakes…
But now it is perfect.
Thanks @sid_ranjan and @jineshparakh @cubefreak777 @shahayush2507

1 Like

@cubefreak777 no he did not
he changed a lot of things he was printing 1 and 0 under a for loop but we were supposed to print only once.

Thanks guys for improving me…
I will continue my work and will create more interesting push_back contests.
Love this CodeChef coding community

you know what you’re saying right ? aren’t there multiple test-cases, so you have to loop any ways right ?

@references ok and what’s wrong in this solution ???

https://www.codechef.com/viewsolution/40735497

python is slow and time limit is a little tight hence TLE

1 Like

@cubefreak777 are you ok???

this was his code–

#include<bits/stdc++.h>
using namespace std;
int main()
 {
	ios_base::sync_with_stdio(false);
   	cin.tie(NULL);
   	cout.tie(NULL);
   	int n,t=5000000;
	for(int i=1;i<=t;i++)
	{
		if(i%3==0)cout<<1<<"\n";
		else cout<<0<<"\n";
	}

}

Yeah what’s wrong this code tests for 500000 test-cases and input stuff hasn’t been written cause it was for testing purposes ?

Hey dude,
I said that it was a mistake.
And for test case generation and testing purpose, I used that code.
and by mistakenly posted here.
I updated everything and you still arguing.

Use fast IO in C++ or any other specific fast IO techniques in particular language

1 Like

@references I am not arguing because you posted the test code as the solution by mistake the problem is that this solution passes as the correct answer for the problem which is wrong as per the problem statement.
check the input output format given in the problem statement and still, this solution gives AC.
HOW???