DEV Community

star1-aysi
star1-aysi

Posted on

c++ code error checking

There is sequence 1, 12, 123, 1234, ..., 12345678910, ... . Given first N elements of that sequence. You must determine amount of numbers in it that are divisible by 3.

include

using namespace std;
int main() {
long long int N,sum=1,count=0;
cin>>N;
long long int a[N];/maybe this data type can cause problem but i changed nothing changed./
for (int i=0;i<N;i++){
a[i]=sum;
sum=sum*10+(i+2);
if (a[i]%3==0)
count++;
}
cout<<count;

return 0;
Enter fullscreen mode Exit fullscreen mode

}
what is my mistake in this code. It fits till 7th test

Top comments (0)