13 条题解

  • 8
    @ 2023-7-13 15:20:51

    #include<bits/stdc++.h> using namespace std; long ikun(long x)//劈荆成王,伴kun远航 {long n=1,s=0,y=0; while(s<=x) { s=s+pow(n,2); if(s>x) break; else {y++;n++;} } return y; } int main() { long a; cin>>a; cout<<ikun(a); }

  • 4
    @ 2023-10-18 9:29:26
    a=int(input())
    b=0
    c=1
    flag=True
    while flag:
        b+=c**2
        if b<=a:
            c+=1
        else:
            c-=1
            flag=False
    
    print(c)
    
    • 2
      @ 2025-3-5 13:00:04

      我是213

      • 2
        @ 2024-9-25 17:20:40
        a=int(input())
        b=0
        c=1
        flag=True
        while flag:
            b+=c**2
            if b<=a:
                c+=1
            else:
                c-=1
                flag=False
        
        print(c)
        错了牟翔宇吃两吨
        
        • 2
          @ 2023-7-16 19:57:50
          #include <iostream>
          #include <math.h>
          using namespace std;
          
          int main()
          {
              int n,x,i,m=0;
              cin >>x;
              for(i=1;i>0;i++){
                  m+=pow(i,2);
                  if(m>x){
                      n=i-1;
                      break;
                  }
              }
              cout <<n;
          }
          
          • 2
            @ 2023-7-12 15:24:44
            #include <bits/stdc++.h>
            using namespace std;
            int bif(int a)
            {
            	int z=0,i,b=0,c[1000]={0};
            	for(i=1;i<a;i++)
            	{
            		c[i]=i;
            		b+=c[i]*c[i];
            		z++;
            		if(b>a)
            			break;
            	
            	}
            	return z-1;
            }
            
            int main() 
            {
            	int k,f;
            	cin>>k;
            	cout<<bif(k)<<endl;
            return 0;
            }
            
            • 1
              @ 2024-12-26 9:44:52

              本题最优时间复杂度为O(logN)

              Σi=1i2\Sigma_{i=1} {i^2} = n(n+1)(2n+1)/6

              结合二分可达到log级别复杂度

              AC代码

              #coding: utf-8
              n:int = int(input())
              def judge(x: int):
                  return x*(x + 1)*(2 * x + 1) <= 6 * n
              left = 0
              right = n+1
              while (right - left > 1):
                  mid = int((left + right) / 2)
                  if (judge(mid)):
                      left = mid
                  else:
                      right = mid
              print("%d\n" % (left))
              
              
              
              • 1
                @ 2024-9-25 17:19:34
                a=int(input())
                b=0
                c=1
                flag=True
                while flag:
                    b+=c**2
                    if b<=a:
                        c+=1
                    else:
                        c-=1
                        flag=False
                
                print(c)
                错了何格吃一吨
                
                • 1
                  @ 2023-8-26 10:44:40
                  #include <iostream>
                  #include <cmath>
                  using namespace std;
                  int main() 
                  {
                  	long long x;
                  	cin >> x;
                  	long long n = 1;
                  	long long sum = 0;
                  	while (sum + n * n <= x) 
                      {
                  		sum += n * n;
                  		n++;
                  	}
                  	cout << n - 1 << endl;
                  	return 0;
                  }
                  

                  zZ~

                  • 1
                    @ 2023-7-16 19:44:28
                    #include <iostream>
                    #include<cmath>
                    using namespace std;
                    int n,x,m;
                    int main() {
                        cin>>x;
                        for(n=1;n<=x;n++){
                            m=m+pow(n,2);
                            if(m>x){
                                cout<<n-1;
                                break;
                            }
                        }
                    return 0;
                    }
                    

                    c++

                    • 1
                      @ 2023-7-16 19:14:50
                      #include <iostream>
                      #include <cmath>
                      using namespace std;
                      int k=0;int x;
                      int f(int n)
                      {
                      
                          k+=pow(n,2);
                          if(k>=x)
                          {
                              return n;
                          }
                          n++;
                          return f(n);
                      }
                      int main()
                      {
                      
                      
                         cin>>x;
                         cout<<f(0)-1;
                          return 0;
                      }
                      
                      
                      • 0
                        @ 2024-10-16 10:38:55
                        a=int(input())
                        n=1
                        m=0
                        while m<=a:
                            m+=n**2
                            n+=1
                        print(n-2)
                        

                        python

                        • 0
                          @ 2024-9-23 11:32:45

                          x=int(input())

                          for i in range(1,x):

                          if i*(i+1)(2i+1)/6<=x and (i+1)(i+2)(2*i+3)/6>x:

                          print(i)

                          • 1

                          信息

                          ID
                          53
                          时间
                          1000ms
                          内存
                          128MiB
                          难度
                          4
                          标签
                          递交数
                          1657
                          已通过
                          784
                          上传者