CHEFFED - Editorial

S(X)+S(S(X))≤97S(X)+S(S(X))≤97 , we just need to iterate from XX = N−97N−97 to N??? but how?/
how you can find the interval of X.
CAN ANYONE PROVE IT?

In this question output of test case 999999969 is 2 in this solution https://www.codechef.com/viewsolution/10893318
while the answer should be 3.
Still got AC

What does O(97) even mean? Shouldn’t it be O(1)?

1 Like

In case you write complexity like this, it sounds like you can find S(x) in O(1).

In general, why not to write it like log^2(N) or something like that?

The following C++ code when compiled gives Time limit exceeded. Can anyone help me out?

#include

using namespace std;

int main()
{
int N,X,ctr=0,val,val2;
cin>>N;
for(X=0;X<N;X++){
int sum1=0,sum2=0,sumv=0;
val=X;
while(val!=0){
sum1=sum1+val%10;
val=val/10;
}
val2=sum1;
while(val2!=0){
sum2=sum2+val2%10;
val2=val2/10;
}
sumv=X+sum1+sum2;
if(sumv==N){
ctr++;
}
}
cout<<ctr;
return 0;
}