Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std ;
- int val ;
- bool once_used = false ;
- int superDigit(string n, int k) {
- if (!once_used){
- string adder = n ;
- for (int i = 1 ; i < k; i++) {
- n+=adder;
- }
- once_used = true ;
- }
- if (n.size() == 1){return stoi(n);}
- else {
- int total = 0 ;
- for (int i = 0 ;i < n.size(); i++) {
- total +=n[i] - '0';
- }
- n = to_string(total);
- val = superDigit( n, k) ;
- cout << val;
- }
- ///cout << val ;
- return val ;
- //return total ;
- }
- int main() {
- string n ;
- cin >> n ;
- int k ;
- cin >> k ;
- cout << superDigit(n, k);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement