Author: Anurag
Tester: Anurag
Editorialist: Anurag
DIFFICULTY:
EASY,MEDIUM,GREEDY,STRING,CAKEWALK, SIMPLE
PREREQUISITES:
Math ,String
PROBLEM:
You have given range N and M you have to find number of element which is multiple of both 9 and 3 and print count of it N and M are inclusive
EXPLANATION:
we have given some range of number and we have to just find out the number which is multiple of 3 and 9 and count how many numbers are multiple of 3 and 9 both and print the count
for example
3 20
we have given range between 3 to 20 in this range only two numbers are multiple of both 3 and 9 which is 9 and 18 hence the output is 2
SOLUTIONS:
Setter's Solution
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t–)
{
int n,m;
cin>>n>>m;
int cnt=0;
for(int i=n;i<=m;i++){
if((i%3==0) && (i%9==0)){
cnt++;
}
}
cout<<cnt;
cout<<endl;
}
return 0;
}
Tester's Solution
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t–)
{
int n,m;
cin>>n>>m;
int cnt=0;
for(int i=n;i<=m;i++){
if((i%3==0) && (i%9==0)){
cnt++;
}
}
cout<<cnt;
cout<<endl;
}
return 0;
}
[details=“Editorialist’s Solution”]
indent whole code by 4 spaces#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t–)
{
int n,m;
cin>>n>>m;
int cnt=0;
for(int i=n;i<=m;i++){
if((i%3==0) && (i%9==0)){
cnt++;
}
}
cout<<cnt;
cout<<endl;
}
return 0;
}[/details]