5 solutions

  • 3
    @ 2024-10-26 16:12:12
    #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
        int n;
        cin>>n;
        int day=0;
        int coins=0;
        for(int i=1;i<=n;i++) //枚举发多少枚金币 
        {
            for(int j=1;j<=i;j++) //发i枚金币的第j天 
            {
                day++; //天数增加 
                coins+=i; //金币数目增加 
                if(day==n) //已经发了对应的天数了 
                {
                    cout<<coins;
                    return 0;   
                }   
            }   
        }   
        return 0;
    }
    
    
    • 2
      @ 2025-1-4 15:52:02
      
      #include<bits/stdc++.h>
      using namespace std;
      int main()
      {
          int a,b=0,c=0;
          cin>>a;
          	for(int i=1;i<=a;i++)
          	{
              	for(int j=1;j<=i;j++)
              	{
                  	b++;
                  	c+=i;
                  	if(b==a)
                  	{
                  		cout<<c;
      					return 0;	
      				}
              	}
          	}
          return 0;
      }
      • 0
        @ 2026-7-14 11:46:50

        [InternetShortcut] URL=https://lizikid.top/discuss

        • 0
          @ 2026-3-14 11:27:56
          #include<bits/stdc++.h>
          using namespace std;
          int main()
          {
          	int a,s=0,t=0;
          	cin>>a;
          	for(int i=1;i<=a;i++)
          	{
          		for(int j=1;j<=i;j++)
          		{
          			t++;
          			s+=i;
          			if(t==a)
          			{
          				cout<<s;
          				return 0;
          			}
          		}
          	}
          	return 0;
          }
          
          • -7
            @ 2024-10-7 11:47:04
            #include<iostream>
            using namespace std;
            int main()
            {
                int n;
                cin >> n;
                int h=0;//记录前一个i
                int l = 1 , i, sum = 0;
                for(i=1;i<=n;i+=l)//这个过程请读者带数运行以下就理解了
                {
                    sum+=l*(i-h);//总的金币相加
                    l++;//下一次给的金币数
                    h=i;//记录前一个i,(i-h)就可以得到发工资都相同得天数
                }
                if(i!=n)//如果不相等就说明sum小于真实值,就是不满足下一个同样工资得天数!=(i-h)个;
                {
                    sum+=(n-h)*l;//将剩余得加起来;
                }
                cout<<sum;
            }
            
            
            • 1

            Information

            ID
            886
            Time
            1000ms
            Memory
            256MiB
            Difficulty
            3
            Tags
            (None)
            # Submissions
            248
            Accepted
            89
            Uploaded By