cf599D Spongebob and Squares(推公式,枚举)

Unity3D 2022版如何一键安装Newtonsoft.Json?最新Package Manager教程 本文详细介绍了在Unity3D 2022及以上版本中,如何通过Package Manager一键安装和配置Newtonsoft.Json(Json.NET)。教程涵盖了从打开Package Manager、搜索并安装正确包源,到验证安装和基础使用的完整流程,旨在帮助开发者以现代化、可靠的方式集成这一强大的JSON处理框架,提升开发效率并规避手动导入的常见问题。 阅读详情

Spongebob is already tired trying to reason his weird actions and calculations, so he simply asked you to find all pairs of n and m, such that there are exactly x distinct squares in the table consisting of n rows and m columns. For example, in a 3 × 5 table there are 15 squares with side one, 8 squares with side two and 3 squares with side three. The total number of distinct squares in a 3 × 5 table is 15 + 8 + 3 = 26.

Input
The first line of the input contains a single integer x (1 ≤ x ≤ 1018) — the number of squares inside the tables Spongebob is interested in.

Output
First print a single integer k — the number of tables with exactly x distinct squares inside.

Then print k pairs of integers describing the tables. Print the pairs in the order of increasing n, and in case of equality — in the order of increasing m.

Sample test(s)
input
26
output
6
1 26
2 9
3 5
5 3
9 2
26 1
input
2
output
2
1 2
2 1
input
8
output
4
1 8
2 3
3 2
8 1
Note
In a 1 × 2 table there are 2 1 × 1 squares. So, 2 distinct squares in total.
这里写图片描述

In a 2 × 3 table there are 6 1 × 1 squares and 2 2 × 2 squares. That is equal to 8 squares in total.

这里写图片描述
就是一个n*m的矩形,里面有多少个不同的正方形。现在给出不同 正方形的个数n,让你求所有满足不同正方形个数为n的矩形长和宽。

推公式,推一会就出来了。首先是当n大于m是,n每加一,正方形数量只会增加m + m - 1 + m - 2 + …… + 1 = m*(m + 1)/2;
就是f(n + 1,m) = f(n,m) + m*(m + 1)/2;
然后矩形又是对称的,就是n和m是可以互换的(如果m大于n,还是等价于上面那个式子,互换就可以了)
接下来就是搞f(n,n)的值,当时列了一下递推式,求和太麻烦,然后我就看看1,2,3,4的规律,发现是平方和,验证了一下是对的。
那么这题就好搞了,首先确定m(f(m,m) <= x),然后判断x - f(m,m)的差值是否可以被m*(m + 1)/2整除,如果可以,这个就是答案,然后就是枚举了,根据公式,应该是1e6的复杂度。
枚举之后个数乘以2,输出长宽,倒着再输一次,因为答案的矩形都是对称的。
还有一点注意就是如果f(m,m)恰好是x的话,这个本身就是一个正方形,那么最后答案是乘以2之后还要-1。

#include<cstdio>
#include<cstring>
#include<iostream>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>
#include<map>
#include<vector>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int maxn = 1005;
vector<ll>vt;
ll work(ll n)
{
    return n*(n + 1)*(2*n + 1)/6;
}
int main()
{
    #ifdef LOCAL
    freopen("C:\\Users\\ΡΡ\\Desktop\\in.txt","r",stdin);
    //freopen("C:\\Users\\ΡΡ\\Desktop\\out.txt","w",stdout);
    #endif // LOCAL
    ll n;
    scanf("%I64d",&n);
    ll i = 1;
    ll ans = 0;
    bool flag = false;
    while(work(i) <= n&&i*i <= n)
    {
        ll temp = work(i);
        ll mod = i*(i + 1)/2;
        if((n - temp)%mod == 0)
        {
            vt.push_back(i);
            vt.push_back(i + (n - temp)/mod);
            ans++;
            if(n == temp)flag = true;
        }
        i++;
    }
    ans = ans*2;
    if(flag)ans--;
    printf("%I64d\n",ans);
    for(ll i = 0;i < vt.size();i = i + 2)
    {
        printf("%I64d %I64d\n",vt[i],vt[i + 1]);
    }
    for(ll i = vt.size() - 1;i >= 0;i = i - 2)
    {
        if(vt[i] != vt[i - 1])
        printf("%I64d %I64d\n",vt[i],vt[i - 1]);
    }
    return 0;
}
大模型运维实战:从GPU选型到推理服务稳定落地 大模型服务进入生产环境后,运维对象从传统进程转向GPU显存、KV Cache、推理吞吐等动态资源。显存利用率、首token延迟、并发队列深度等指标,直接影响模型服务的质量与成本。理解推理框架的内存分配机制、掌握监控告警与自动化扩容手段,是保障服务稳定的关键。这类能力广泛应用于企业私有化部署、智能客服、知识库问答等场景,帮助运维团队从被动救火转向主动容量规划与性能调优。本文围绕大模型运维的完整路线,梳理从硬件选型、推理部署到监控排障的实战经验,并算清一份真实项目的长期成本账。 阅读详情

相关推荐

Qi标准无线充学习笔记

负载调制主要通过接收端向后散射调制计数使得功率信号改变,两者通过线圈的电压和电流的变化量来传输信号。下面是要求稳定电流的变化量不得超出8ma,判断稳定的时间至少要在150us稳定电压的变化量不得超出110mv,判断稳定的时间至少要在150us高低电流变化量至少需要15mA,判断稳定的时间至少要在100us,主线圈电流采样的时间是在半桥转换的1/4周期刻测量的高低电压变化量至少需要200mV,判断稳定的时间至少要在100us。

m0_73991989的博客 1010

游戏角色互动系统开发:碰撞检测与物理引擎实践指南

碰撞检测是游戏开发中的核心技术,通过算法判断游戏对象是否发生接触。其原理基于几何计算和空间分割,能够实现角色间的物理互动。在游戏引擎中,碰撞检测为角色行为控制提供基础支撑,确保互动的真实性和流畅性。本文以mosquito项目为例,展示多角色系统的碰撞检测实现,涵盖蚊子吸附、老鼠撞击等特色互动机制。通过物理引擎集成和性能优化,该项目为游戏开发者和物理模拟爱好者提供了实用的技术参考,适用于角色互动系统、智能体行为模拟等应用场景。

weixin_34401479的博客 424

JS实例(三)图片的缓慢放大和缩小

  我们经常能看到在一些网站中可以通过按钮实现对图片的放大或者缩小,也有可能是鼠标经过时图片放大。在本例中就是通过JavaScript实现图片的放大和缩小。   首先是进行简单的页面布局 1 <div class="imagedispose"> 2 <img src="1.jpeg" id="imaged" width="400px" height="3...

weixin_34235105的博客 313

【CodeForces - 599D】Spongebob and Squares(推公式+枚举)

题意: 在一张3*5的网格图中,有15个1*1的矩阵,有8个2*2的矩阵,有3个3*3的矩阵,一共有26个不同的正方形。 现在已知一个矩形中包含一定数量的正方形,问这个矩形有多少种不同的可能。 Input 第一行包含一个整数x(1 ≤ x ≤ 1018)— 表示矩形中包含的正方形个数。 Output 输出整数k表示有多少种不同的矩形满足条件 之后输出k对整数,每对整数描述一...

__似水流年__的博客 326

域控制器开发避坑实录:从硬件设计到软件集成的5个关键挑战

本文深入剖析了域控制器开发中的5大关键挑战,从硬件选型到软件集成,涵盖智能驾驶芯片选择、实时性优化、AUTOSAR架构适配等核心问题。通过实战案例和数据对比,为工程师提供避坑指南,助力提升开发效率和系统可靠性。

weixin_29258297的博客 394

ABAP Secure Storage 在事务码 SM59 中的应用

系统管理人员在进行维护时,应关注相关日志信息,及时发现可能出现的安全异常,并针对不同安全等级的操作制定相应的备份与恢复策略,以降低潜在风险。该区域在设计上具备高度隔离性,仅允许经过授权的组件访问。保存后,系统会将密码存储在 Secure Storage 中,这种处理方式充分体现了 SAP 标准程序在安全设计上的考量。对于系统管理员而言,这种机制在日常维护与审计中提供了有力的支持,可以通过比对存储数据的哈希值或其他完整性校验手段,及时发现异常变动,保障系统长期稳定运行。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 670

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

time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Spongebob is already tired trying to reason his weird actions and calculatio...

159

【MATLAB代码】蚁群算法(Ant Colony Optimization, ACO)路径规划(避障)仿真程序,订阅专栏后可直接查看完整源代码

基于蚁群算法的路径规划系统。可自定义起点、终点和障碍物地图,系统通过蚁群算法自动计算最优路径,并输出路径坐标、障碍物地图和收敛曲线。完整MATLAB源代码直接运行。适用于复杂障碍环境下的路径优化问题。

985工科博士毕业,专攻定位、导航和滤波等算法研究。从业10年,主要使用MATLAB 3091

codeforces 599D. Spongebob and Squares【推公式+暴力枚举】

D. Spongebob and Squares time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Spongebob is already tired trying

Joeferyの博客 784

Linux故障排查和性能优化面试题及参考答案

在 Linux 系统中,负载(Load Average)是衡量系统繁忙程度的一个重要指标,它表示系统在特定时间间隔内运行队列中的平均进程数。负载值反映了系统当前的工作压力,主要包括 CPU 等待运行的进程数量和处于不可中断睡眠状态(通常是等待 I/O 操作完成)的进程数量。负载平均值通常有三个数值,分别代表过去 1 分钟、5 分钟和 15 分钟内的系统平均负载。例如,在使用uptime命令或查看文件时,会看到类似这样的输出,这三个数值依次表示过去 1 分钟、5 分钟和 15 分钟的负载平均值。

大模型大数据攻城狮的专栏 1081

【PCIe 总线及设备入门学习专栏 6.1 -- PCIe MCTP】

MCTP 是由 DMTF(Distributed Management Task Force)定义的协议,用于提供设备和主机间基于不同传输层(如 PCIe、I²C、USB 等)的管理消息通信能力。在 PCIe 环境下,MCTP 消息作为的一种特殊形式传输,并被赋予唯一的 VDM Code 值0000b,以区别于其他 VDM。MCTP 在 PCIe 环境中作为一种基于 Type 1 VDM 的管理通信协议,提供了设备与主机之间的灵活数据传输能力。

CodingCos的博客 2127

Codeforces 599D Spongebob and Squares 【公式推导 暴力】

D. Spongebob and Squares time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Spongebob is already tired trying

世界很大 961

100个Python实战项目(七)实现摩斯密码翻译器

作者主页:海拥 作者简介:优快云全栈领域优质创作者、HDZ核心组成员、蝉联C站周榜前十 粉丝福利:往期获奖记录 每周送6~9本书,不定期送各种小礼品(搪瓷杯、抱枕、鼠标垫、马克杯等) 摩斯密码是一种将文本信息作为一系列通断的音调、灯光或咔嗒声传输的方法,无需特殊设备,熟记的小伙伴即可直接翻译。它以电报发明者Samuel F. B. Morse的名字命名。 算法 算法非常简单。英语中的每个字符都被一系列“点”和“破折号”代替,或者有时只是单数的“点”或“

努力是为了站在万人之中,成为别人的光 1万+

[cf 599D] Spongebob and Squares

据题意:   $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,其余反过来输出即可 #include <iostream> #include <algorit...

weixin_30587025的博客 102

SIMATIC S7-1200, S7-1500 PID 控制[手册]

SIMATIC S7-1200, S7-1500 PID 控制[手册]

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

Codeforces Round #332 (Div. 2)-D. Spongebob and Squares

原题链接 D. Spongebob and Squares time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Spongebob is already

L. 270

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

Codeforces 599D Spongebob and Squares 公式,暴枚

题意 题解 Codeforces 599D Spongebob and Squares 题意 给出x,求全部长n宽m的正方形网格图,里面有x个正方形. 题解 首先推长nnn宽mmm的网格图的正方形个数的公式. 不妨假设n≤m.对于边长i=1→n的正方形来说,每一种都有(n−i+1)(m−i+1)个.nm+(n−1)(m−1)+(n−2)(m−2)+(n−...

Fuko_Ibuki的博客 1万+

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

Codeforces 599D Spongebob and Squares(枚举 + 数学)

@(K ACMer)题意:给你一个数k,(k<1e18),表示矩形不同的正方形的个数,求满足k的所有矩形.分析:求出公式,枚举实现即可. 这个题,比赛的时候错误的认知了复杂度,以为1e18必须要logn的算法才行,其实开次3根号也好的.#include <iostream> #include <cstdio> #include <cstring> #include <set> #include <

JIBANCANYANG 867

Codeforces 599D:Spongebob and Squares

D. Spongebob and Squares time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Spongebob is already tired...

weixin_34186128的博客 155

Codeforces 599D Spongebob and Squares(数学)

D. Spongebob and Squares Spongebob is already tired trying to reason his weird actions and calculations, so he simply asked you to find all pairs of n and m, such that there are exactlyxdistin...

dituonian8372的博客 194

607A Chain Reaction(DP)

There are n beacons located at distinct positions on a number line. The i-th beacon has position ai and power level bi. When the i-th beacon is activated, it destroys all beacons to its left (direction

Techay的博客 1019

cf599C Day at the Beach(区间合并)

C. Day at the Beach time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output One day Squidward, Spongebob and Patrick decided to go to the beach. U

Techay的博客 755

Caesar's Legions(记忆化搜索)

Gaius Julius Caesar, a famous general, loved to line up his soldiers. Overall the army had n1 footmen and n2 horsemen. Caesar thought that an arrangement is not beautiful if somewhere in the line there

Techay的博客 731

Matrix

You have a string of decimal digits s. Let’s define bij = si·sj. Find in matrix b the number of such rectangles that the sum bij for all cells (i, j) that are the elements of the rectangle equals a in

Techay的博客 712

Dreamoon and WiFi

 Dreamoon is standing at the position 0 on a number line. Drazil is sending a list of commands through Wi-Fi to Dreamoon's smartphone and Dreamoon follows them. Each command is one of the foll

Techay的博客 675

Cut Ribbon

 Cut Ribbon time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Polycarpus has a ribbon, its length is n.

Techay的博客 602

ZgukistringZ

 Professor GukiZ doesn't accept string as they are. He likes to swap some letters in string to obtain a new one. GukiZ has strings a, b, and c. He wants to obtain string k by swapping some l

Techay的博客 596
上一篇: cf599C Day at the Beach(区间合并)
下一篇: Writing Code(DP)
Techay
博客等级 码龄11年 11粉丝 174原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值