@Arjun sir
please check this
If we write like this
int main()
{
for(int i=0; i<=100;i++)
{
if (i % 3 == 0 && i%5 == 0)
{
printf("GreatIndia");
}
}
return 0;
}
Divisible by $3$ and divisible by $5$ means divisible by $\text{LCM(3,5)=15}$
${\color{Green}{i=0,15,30,45,60,75,90} }$
We print ${\color{Magenta} {\text{GreatIndia}}}$ $7$ times.
If we write like this
int main()
{
for(int i=0; i<=100;i++)
{
if (i % 3 == 0 || i%5 == 0)
{
printf("GreatIndia");
}
}
return 0;
}
Divisible by $3$ (or) divisible by $5$
For $i=0$ we print ${\color{DarkOrange}{"GreatIndia"} }$
and from ${\color{Purple} {i=1,2,3,...,100}}$
we can apply principle of mutual inclusion and exclusion
${\color{Magenta} {|A\cup B|=|A|+|B|-|A\cap B|}}$
Here $A=3,B=5$
$|3\cup 5| = |3| + |5| - |3\cap 5|$--------->$(1)$
Now,$|3| =\left \lfloor \frac{100}{3} \right \rfloor=33$
$|5|=\left \lfloor \frac{100}{5} \right \rfloor=20$
$|3\cap 5|=\left \lfloor \frac{100}{LCM(3,5)} \right \rfloor=\left \lfloor \frac{100}{15} \right \rfloor=6$
Put all values in equation $(1)$ and we can
$|3\cup 5|=33+20-6=53-6=47$
So total we can print $1+47=48$
We print ${\color{Red} {\text{GreatIndia}}}$ $48$ times.
But given question in a different way
So,we print like this
$i=0,0$---->(1)
$i=3,5$--->(2)
$i=9,10$----->(3)
$i=15,15$----->(4)
$i=18,20$---->(5)
$i=24,25$---->(6)
$i=30,30$---->(7)
$i=33,35$---->(8)
$i=39,40$---->(9)
$i=45,45$---->(10)
$i=48,50$---->(11)
$i=51,55$---->(12)
$i=60,60$---->(13)
$i=63,65$---->(14)
$i=69,70$---->(15)
$i=75,75$---->(16)
$i=78,80$---->(17)
$i=84,85$---->(18)
$i=90,90$---->(19)
$i=93,95$---->(20)
$i=99,100$---->(21)
Why i neglect i = 12 case?
When $i=12$ it is divisible by $3$
So it print ${\color{Red}{\text{Great}} }$
But after that $i$ become $15$ then it is divisible by $3$ as well as $5$
So,it will print ${\color{DarkOrange}{\text{GreatIndia}} }$
So, finally answer is $21$