先确定M的大致范围后即可求。

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#define LL __int64
#define N 60000 LL square[N];
LL spre[N]; void init(){
spre[0]=0; spre[0]=0;
for(LL i=1;i<N;i++){
square[i]=i*i;
spre[i]=spre[i-1]+i*(2*i+1);
}
} int main(){
init();
int T,n;
scanf("%d",&T);
while(T--){
scanf("%d",&n);
LL p=(LL)sqrt(n*1.0);
if(square[p+1]-p-1<n)
p++;
LL g=n-(square[p]-p)+square[p];
LL su=spre[p-1]+p*(g-square[p]+1);
printf("%I64d %I64d\n",g,su);
}
}

  

HDU 4342的更多相关文章

  1. hdu 4342 History repeat itself(数学题)

    题目链接:hdu 4342 History repeat itself 题意: 让你找第a个非完全平方数m,并且求前m个数的开方向下取整的和. 题解: 第一个问题: 假设第a个非平方数是X,X前面有n ...

  2. HDU 4342——History repeat itself——————【数学规律】

    History repeat itself Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HDU. O ...

  3. 【HDU - 4342】History repeat itself(数学)

    BUPT2017 wintertraining(15) #8C 题意 求第n(n<2^32)个非完全平方数m,以及\(\sum_{i=1}^m{\lfloor\sqrt i\rfloor}\) ...

  4. 2012 #5 History repeat itself

    History repeat itself Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I6 ...

  5. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  6. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  7. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  8. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  9. HDU 4006The kth great number(K大数 +小顶堆)

    The kth great number Time Limit:1000MS     Memory Limit:65768KB     64bit IO Format:%I64d & %I64 ...

随机推荐

  1. Linux - Nginx的集群与负载均衡

    Nginx的集群与负载均衡 集群就是一群人干同样的活,负载均衡就是保证每个人都干得差不多.或者大人干得多一些,小孩干得少一些. Nginx实现负载均衡很方便. 准备三台服务器,一台是用于访问图片(66 ...

  2. friend(hdoj 1719)

    Friend Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Sub ...

  3. Java-Zipkin:Zipkin 介绍

    ylbtech-Java-Zipkin:Zipkin 介绍 1.返回顶部 1. 介绍 Zipkin 是一款开源的分布式实时数据追踪系统(Distributed Tracking System),基于 ...

  4. [计蒜客] tsy's number 解题报告 (莫比乌斯反演+数论分块)

    interlinkage: https://nanti.jisuanke.com/t/38226 description: solution: 显然$\frac{\phi(j^2)}{\phi(j)} ...

  5. 21. Merge Two Sorted Lists[E]合并两个有序链表

    题目 Merge two sorted linked lists and return it as a new list. The new list should be made by splicin ...

  6. SMTP协议详解

    简单邮件传输协议 (Simple Mail Transfer Protocol, SMTP) 是在Internet传输email的事实标准. SMTP是一个相对简单的基于文本的协议.在其之上指定了一条 ...

  7. Kaggle爆文:一个框架解决几乎所有机器学习问题

      上周一个叫 Abhishek Thakur 的数据科学家,在他的 Linkedin 发表了一篇文章 Approaching (Almost) Any Machine Learning Proble ...

  8. windows7 安装 choco

    windows7 安装 choco: cmd下: @"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -N ...

  9. html+css布局整理笔记

    基本概念 布局模型 流动模型(Flow) 浮动模型(Float) 层模型(Layer) 流动模型 默认的网页布局模式,流动布局模型有两个比较典型的特征: 第一,块级元素都会在所处的包含元素内自上而下按 ...

  10. 【Oracle】DBA_AUDIT_TRAIL表SES_ACTIONS字段对应的操作列表

    SES_ACTIONS字段共包含16个字符,初始状态都为“-”,当被审计的对象被操作后,SES_ACTIONS会在相应的位置作出标识,标识为“S”的代表操作成功,标识为“F”的代表操作失败,16个位置 ...