-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3035562
commit 4420bc4
Showing
1 changed file
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
int super(long long int num) | ||
{ | ||
if(num<=9) | ||
{ | ||
return num; | ||
} | ||
long long int sum=0; | ||
long long int m=0; | ||
|
||
while(num!=0) | ||
{ | ||
|
||
m=num%10; | ||
sum=sum+m; | ||
num=num/10; | ||
} | ||
return super(sum); | ||
} | ||
|
||
// Complete the superDigit function below. | ||
int superDigit(string n, int k) | ||
{ | ||
long long int sum=0; | ||
|
||
for(int i=0; i<n.size(); i++) | ||
{ | ||
sum += n[i] - '0'; | ||
} | ||
|
||
return super(sum*k); | ||
|
||
} |