2443. sunny的烦恼

Suzuki_Yuuta
int f(int n) {
    if (n < 10) {
        return n;
    } 
    return f((n % 10) + f(n / 10));
}
MichaelChen

f(49) = f(13) = f(4) = 4.

我太难了
for _ in range(int(input())):
    n = int(input())
    print((n-1) % 9+1 if n else 0)
51174500037

include

using namespace std;
int num;

int main()
{
int T,i,total = 0;
cin>>T;
while(T–)
{

    cin>>num;
    total = num;
    while(total>=10){
        total = 0;
        while(num){
            total += num%10;
            num /= 10;
        }
        num = total;
    }


    cout<<total<<endl;
}
return 0;

}

Mr.wu_

if(sum<=9) return sum; else return f(f(sum));

wty24601

T = int(input())
for i in range(T):
n = int(input())
if n == 0:
print(0)
elif n % 9 != 0:
print(n % 9)
else:
print(9)

你当前正在回复 博客/题目
存在问题!