这两个代码哪里不一样啊,运算不一样,我哭

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<LL, LL> PII;
const int N=3010;
int a[N];
int main()
{
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int n;
cin>>n;

for(int i=1; i<=n; i++)
{
    int x=i;
    int cnt=0;

    while(1)
    {
        int num=0;
        if(x==0) break;
        if(x<10)
        {
            x=0;
            cnt++;
        }
        else
        {
            int y=x;
            while(y)
            {
                num+=y%10;
                y/=10;
            }
            cnt++;
        }
        x=num;
    }
    a[i]=cnt;
}
int res=0;
for(int i=1; i<=n; i++)
{
    for(int j=i+1; j<=n; j++)
    {
        for(int k=j+1; k<=n; k++)
        {
            if(a[i]<a[j]&&a[j]<a[k])
            {
                res++;
            }
        }
    }
}
cout<<res<<endl;
return 0;

}

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<LL, LL> PII;

const int N = 3010;

int a[N];

int main()
{
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int n;
cin >> n;

for (int i = 1; i <= n; i ++)  // 预处理
{
    int x = i;
    int cnt = 0;
    while (1)
    {
        int num = 0;
        if (x == 0)
            break;
        if(x < 10)
        {
            x = 0;
            cnt ++;
        }
        else
        {
            int y = x;
            while (y)
            {
                num += y % 10;
                y /= 10;
            }
            cnt ++;
        }
        x = num;
    }
    a[i] = cnt;
}
int res = 0;
for (int z = 1; z <= n; z ++) // 暴力查找
    for (int y = z + 1; y <= n; y ++)
        for (int x = y + 1; x <= n; x ++)
            if (a[x] < a[y] && a[y] < a[z])
                res ++;

cout << res << endl;

return 0;

}