Time limit exceeds

#include
using namespace std;
int Dsum(int n){
int sum=0;
while(n!=0){
sum=sum+n%10;
}
return sum;
}
int main() {
int n;
cin>>n;

int x=Dsum(n);
int y=0;

for(int i=2;i*i<=n;i=i++){
	if(n%i==0){
	while(n%i==0){
		y=y+Dsum(i);
		n=n/i;
	}
}
}
if(n>1)
y=y+Dsum(n);

if(x==y)
 cout<<"1";
 else
 cout<<"0";
return 0;

}

Hello @umnah1103_2205d5eee7973385,

In your Dsum function, you are not doing n = n%10,

while(n!=0){
sum=sum+n%10;
n = n%10;
}

same issue after adding n=n/10;

@umnah1103_2205d5eee7973385,

Here, this is wrong way,

for(int i=2;i*i<=n;i=i++)

Correct way:

for(int i=2;i*i<=n;i=++i)

@umnah1103_2205d5eee7973385,

Did it work?

not working, please check this one - include using namespace std; int sod(int n){ int sum=0; while(n!=0){ sum=sum+n%10; n=n/10; } return sum; } int boston(int n){ int s=0; int t=n; while(n%2==0){ s=s+2; n=n/2; } for(int i=3;i<=t/2;i=i+2){ while(n%i==0){ s=s+sod(i); } } if(n>2||s!=sod(t)) return 0; else return 1; } int main() { int n; cin>>n; cout<<boston(n); return 0; }

code executed successfully

1 Like

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.