[数学] [洛谷] P3910 纪念邮票

等差求和公式

根据项数枚举head & tail

eps判整除

//#pragma GCC optimize(2)
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <string>
#include <cstring>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <ctime>
#include <vector>
#include <fstream>
#include <list>
#include <iomanip>
#include <numeric>
using namespace std;
typedef long long ll;

const int MAXN = 1e6 + 10;

#define eps 0.000001

int main()
{
    ios::sync_with_stdio(false);

    cin.tie(0);     cout.tie(0);

    double n, m;

    cin>>n>>m;

    for(int i = sqrt(2 * m); i >= 1; i--)
    {
        int fst = ((2 * m / i) - i + 1 ) / 2;
		
		double tfst = ((2 * m / i) - i + 1 ) / 2;
		
        int lst = i + fst - 1;
		
		if(tfst - double(fst) < eps && fst >= 1 && lst <= n)
		{
			printf("[%d,%d]\n", fst, lst);
		}
        
		
    }

    return 0;
}

猜你喜欢

转载自blog.csdn.net/Zeolim/article/details/81734746