计算x^2=(1^2+2^2+3^2+...+n^2)/n的公式,利用C语言循环的算法怎么才能实现这个问题的呢?

Problem Description
Find the biggest integer n (1 <= n <= N) and an integer x to make them satisfy

Input
The input consists of several test cases. Each test case contains a integer N, 1<=N<=10^18.The input ends with N = 0.

Output
In one line for each case, output two integers n and x you have found.

Sample Input
1
2
0

Sample Output
1 1
1 1

int mun=0
for(int i = 1,i<=n,i++)
{mun=mun+i^2}
x^2=mun/n;

#include <stdio.h>
#include<iostream>
using namespace std;
int main()
{
    long long i,j,k;
    long long N,n,x,sumn2;

    cin>>N;
    while(N!=0)
    {
        n = 0;
        x = 0;
        for(i=N;i>0;i--)
        {
            sumn2 = 0;
            for(j=1;j<=i;j++)
            sumn2 += j*j;
            if(sumn2%i==0)
            {
                k = sumn2 / i;
                x = sqrt(double(k));
                if(x*x == k)
                {
                    n = i;              
                    break;
                }
            }
        }
        cout<<"n="<<n<<"    x="<<x<<endl;
        //cout<<k<<endl;
        //cout<<x*x<<endl;
        cin>>N;
    }
    return 0;
}   

图片说明