Birthday candles (using formula, short and precise)

Birthday Candles Someone has held a birthday party every year since a certain year, and every time he blows out the same number of candles as his age. Counting now, he blew out a total of 236 candles. Excuse me, at what age did he start his birthday party? (The 7th Blue Bridge Cup Group B)

#include<stdio.h>
int main()
{
    
    
    int i,j;
    for( i=1;i<=100;i++)
    {
    
    
        for( j=i;j<=100;j++)
    	{
    
    
            if((i+j)*(j-i+1)/2==236)//等差数列公式 
                printf("%d",i);
        }
    }
    return 0;
}

Guess you like

Origin blog.csdn.net/Helinshan/article/details/109050308