Codeforce 599D Spongebob and squares

Source: Internet
Author: User
Tags define local

The number of blocks that are easy to get NXM is

Then there is the question of summation, enumerating the n≤m of the two.

Then it turns into a*m + c = x. A,m≥0,x≥c. The worst is n^3≤x, as for the middle will not explode, the test of 1e18 is good.

#include <bits/stdc++.h>using namespaceStd;typedefLong LongUll;vector<ull>Ns;vector<ull>MS;//#define LOCALintMain () {#ifdef LOCAL freopen ("In.txt","R", stdin);#endifull x, T, C, a, N, m; Cin>>x; intK =0; //Ns.push_back (1); Ms.push_back (x);    intEqu =0;  for(n =1; ; n++) {T= N (n+1)/2; C= (n) * (n+1)*(2*n+1)/6-NT; if(C > x) Break; A= N (n+1) -T; if((x-c)% A = =0) {m= (X-C)/A; if(M < n) Break;            Ns.push_back (n);            Ms.push_back (m); K++; if(M = =N) {equ=1; Break; }        }    }    if(equ) {k=2*k-1; printf ("%d\n", K); intSZ =ns.size ();  for(inti =0; I < sz; i++) {printf ("%i64d%i64d\n", Ns[i], ms[i]); }         for(inti = sz-2; I >=0; i--) {printf ("%i64d%i64d\n", Ms[i], ns[i]); }    }    Else{k=2*K; printf ("%d\n", K); intSZ =ns.size ();  for(inti =0; I < sz; i++) {printf ("%i64d%i64d\n", Ns[i], ms[i]); }         for(inti = sz-1; I >=0; i--) {printf ("%i64d%i64d\n", Ms[i], ns[i]); }    }    return 0;}

Codeforce 599D Spongebob and squares

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.