Cod sursa(job #1709047)

Utilizator cojocarugabiReality cojocarugabi Data 28 mai 2016 10:41:30
Problema Consecutive Scor 100
Compilator cpp Status done
Runda ONIS 2016 - Runda - 2 - ACM ICPC Romanian Programming Contest Marime 1.44 kb
# include <bits/stdc++.h>
using namespace std;
# define fi cin
# define fo cout
# define x first
# define y second
# define ll long long
# define db long double
# define scn(x) scanf("%I64d",&x)
# define scan(x) scanf("%d",&x)
# define print(x) printf("%d ",x)
# define prnt(x) printf("%I64d ",x);
# define eol printf("\n")
# define IOS ios_base :: sync_with_stdio(0)
# define pe "Possible"
# define ie "Impossible"
# define halt(...) {fo << (__VA_ARGS__) << '\n';exit(0);}
# define rep(n) for (int qwerty = 1;qwerty <= n;++qwerty)
# define pp(n) cerr << #n << " = " << n << '\n'
# define ppp(v) for (auto it : v) cerr << it << ' ';cerr << '\n'
const int mod = 1e9 + 7;
int main(void)
{
    int t;
    ifstream fi("consecutive.in");
    ofstream fo("consecutive.out");
    IOS;
    fi>>t;
    while (t --)
    {
        ll n;
        fi>>n;
        n = n + n;
        auto get = [](ll p,ll u)
        {
            return (1ll * u * (u + 1) - 1ll * p * (p - 1)) / 2;
        };
        vector < pair < int , int > > ans;
        for (int i = 2;1ll * i * i <= n;++i)
        if (!(n%i))
        {
            ll cnt = n / i - i + 1;
            cnt /= 2;
            if (get(cnt,cnt + i - 1) == n/2)
                ans.push_back({i-1,cnt});
        }
        sort(ans.begin(),ans.end());
        fo << (ans.size()) << '\n';
        for (auto it : ans) fo << it.y << ' ' << (it.x + it.y) << '\n';
    }
    return 0;
}