据题意:

  $K=\sum\limits_{i=0}^{n-1}(n-i)*(m-i)$

  $K=n^2m-(n+m)\sum{i}+\sum{i^2}$

  展开化简

  $m=(6k-n+n^3)/(3n^2+3n)$

  枚举n,验证整除,只做n<=m,其余反过来输出即可

  1. #include <iostream>
  2. #include <algorithm>
  3. #include <cstdio>
  4. #include <cstdlib>
  5. #include <cstring>
  6. #include <cmath>
  7. #include <ctime>
  8. #include <vector>
  9.  
  10. using namespace std;
  11.  
  12. vector<pair<long long,long long> >S;
  13.  
  14. int main()
  15. {
  16. long long x,i,Ans=;
  17.  
  18. scanf("%lld",&x);
  19. for(i=;;++i)
  20. {
  21. long long n=i,m=(6LL*x-n+n*n*n)/(*n*n+*n);
  22. if(n>m)break;
  23. if((6LL*x-n+n*n*n)%(*n*n+*n)==)
  24. {
  25. S.push_back(make_pair(n,m));
  26. }
  27. }
  28. if(S.back().first==S.back().second)
  29. {
  30. Ans=-;
  31. }
  32. Ans+=(int)S.size()<<;
  33.  
  34. printf("%lld\n",Ans);
  35. for(i=;i<(int)S.size();++i)
  36. {
  37. printf("%lld %lld\n",S[i].first,S[i].second);
  38. }
  39.  
  40. if(S.back().first==S.back().second)
  41. {
  42. S.pop_back();
  43. }
  44.  
  45. while(!S.empty())
  46. {
  47. printf("%lld %lld\n",S.back().second,S.back().first);
  48. S.pop_back();
  49. }
  50. return ;
  51. }

[cf 599D] Spongebob and Squares的更多相关文章

  1. CF 599D Spongebob and Squares(数学)

    题目链接:http://codeforces.com/problemset/problem/599/D 题意:定义F(n,m)为n行m列的矩阵中方阵的个数,比如3行5列的矩阵,3x3的方阵有3个.2x ...

  2. Codeforces 599D Spongebob and Squares(数学)

    D. Spongebob and Squares Spongebob is already tired trying to reason his weird actions and calculati ...

  3. codeforces 599D Spongebob and Squares

    很容易得到n × m的方块数是 然后就是个求和的问题了,枚举两者中小的那个n ≤ m. 然后就是转化成a*m + c = x了.a,m≥0,x ≥ c.最坏是n^3 ≤ x,至于中间会不会爆,测下1e ...

  4. Codeforces 599D:Spongebob and Squares

    D. Spongebob and Squares time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  5. codeforces #332 div 2 D. Spongebob and Squares

    http://codeforces.com/contest/599/problem/D 题意:给出总的方格数x,问有多少种不同尺寸的矩形满足题意,输出方案数和长宽(3,5和5,3算两种) 思路:比赛的 ...

  6. Codeforces Round #332 (Div. 2) D. Spongebob and Squares 数学题枚举

    D. Spongebob and Squares Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/ ...

  7. Codeforces Round #332 (Div. 2)D. Spongebob and Squares 数学

    D. Spongebob and Squares   Spongebob is already tired trying to reason his weird actions and calcula ...

  8. 【27.40%】【codeforces 599D】Spongebob and Squares

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  9. Codeforces Round #332 (Div. 2) D. Spongebob and Squares(枚举)

    http://codeforces.com/problemset/problem/599/D 题意:给出一个数x,问你有多少个n*m的网格中有x个正方形,输出n和m的值. 思路: 易得公式为:$\su ...

随机推荐

  1. Flink编程练习

    目录 1.wordcount 2.双流警报EventTime 3.持续计数stateful + timer + SideOutputs 4.一定时间范围内的极值windowfunction + che ...

  2. 浅谈IO优化

    三层结构 磁盘(存储).VM(卷管理)和文件系统.专有名词不好理解,打个比方说:磁盘就相当于一块待用的空地:LVM相当于空地上的围墙(把空地划分成多个部分):文件系统则相当于每块空地上建的楼房(决定了 ...

  3. Linux分区方式 及 Xshell远程连接排错

    第1章 远程连接 1.1 Linux远程连接软件 Windows:    Xshell/SecureCRT/Putty mac:         终端ssh命令或iterm2 Android:    ...

  4. E20171015-hm

    quirk   n. 怪癖; 奇事,巧合; 突然的弯曲; propagation  n. 宣传; 传播,传输,蔓延,扩展,波及深度; [生]繁殖法,[地]传导; 培养; immediate  adj. ...

  5. Django基于JWT实现微信小程序的登录和鉴权

    什么是JWT? JWT,全称Json Web Token,用于作为JSON对象在各方之间安全地传输信息.该信息可以被验证和信任,因为它是数字签名的. 与Session的区别 一.Session是在服务 ...

  6. linux 查看内存和cpu

    Linux查看CPU和内存使用情况 在系统维护的过程中,随时可能有需要查看 CPU 使用率,并根据相应信息分析系统状况的需要.在 CentOS 中,可以通过 top 命令来查看 CPU 使用状况.运行 ...

  7. JavaScript--认识DOM

    文档对象模型DOM(Document Object Model)定义访问和处理HTML文档的标准方法.DOM 将HTML文档呈现为带有元素.属性和文本的树结构(节点树). 先来看看下面代码: 将HTM ...

  8. Java常用集合类

    上述类图中,实线边框的是实现类,比如ArrayList,LinkedList,HashMap等,折线边框的是抽象类,比如AbstractCollection,AbstractList,Abstract ...

  9. ANDROID 开发之 SQLite

    SQLite简介 Google为Andriod的较大的数据处理提供了SQLite,他在数据存储.管理.维护等各方面都相当出色,功能也非常的强大.SQLite具备下列特点: 1.轻量级 使用 SQLit ...

  10. c# regex Match Matches MatchCollection 用法

    string text = "1A 2B 3C 4D 5E 6F 7G 8H 9I 10J 11Q 12J 13K 14L 15M 16N ffee80 #800080"; Reg ...