PROBLEM NAME:
DIVISIBILITY
PROBLEM LINK:
(CodeChef: Practical coding for everyone)
DIFFICULTY:
BEGINNER
PREREQUISITES:
BASIC STRING
SOLUTION:
In the given question we need to check whether the number is divisible by 3 or not but the value to the given number is too big to hold in any numeric data type so we will store it in string and traverse on each character convert it into integer and check weather sum of all integers is divisible by 3 or not.
#include <iostream>
#include <string>
#define ll long long int
using namespace std;
int main() {
int tc;
cin>>tc;
while(tc-->0){
string s;
cin>>s;
int n=s.length();
ll sum=0;
for(int i=0;i<n;i++){
char a = s[i];
int ia = a - '0';
sum+= ia;
}
if(sum%3==0){
cout<<"YES"<<"\n";
}else{
cout<<"NO"<<"\n";
}
}
return 0;
}