Click Here to go back to the homepage.

Sum Squared Digits Function Solution:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

long solution(unsigned int input, int base){
    long result = 0;
    while(input  > 0){
        unsigned int remainder = input % base;
        result += remainder * remainder;
        input /= base;
    return result;

int main(){
    int cases;
    scanf("%d", &cases);
    for(int i = 0; i < cases; i++){
        int caseNum, base;
        unsigned int numAsDec;
        scanf("%d %d %d",&caseNum, &base, &numAsDec);
        printf("%d %ld\n", caseNum, solution(numAsDec, base));
    return 0;