[hdu5608]function
题意:$\sum_{d|n}f(d)=n^{2}-3n+2$,求$\sum_{i=1}^{n}f(i)\mod 10^{9}+7$ , $n \leqslant 10^{9}$ $\left( T \leqslant 500\right)$组数据,只有5组>$10^{6}$
题解:看了式子感觉像是反演,但是呢....
令$S(n)=\sum_{i=1}^{n}f(i)$
那么$S(n)=\sum_{i=1}^{n}\sum_{d|i}f(d)=\sum_{i=1}^{n}f(d)\lfloor\frac{n}{d}\rfloor=\sum_{d=1}^{n}\sum_{i=1}^{\lfloor\frac{n}{d}\rfloor} f(d)=\sum_{d=1}^{n}S(\lfloor\frac{n}{d}\rfloor)=\sum_{i=1}^{n}(i-1)*(i-2)$
所以$S(n)=\frac{n*(n-1)*(n-2)}{3}-\sum_{i=2}^{n}f(i)$
所以老套路,预处理$maxn^{\frac{2}{3}}$的S(i),这个可以直接算,总复杂度也是$O(n^{\frac{2}{3}})$
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#define MAXN 5000000
#define mod 1000000007
#define inv 333333336
#define ll long long
using namespace std;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-') f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-''; ch=getchar();}
return x*f;
} int f[MAXN+];
map<int,ll> mp; ll calc(int x)
{
if(x<=MAXN)return f[x];
map<int,ll>::iterator it;
if((it=mp.find(x))!=mp.end())return it->second;
ll sum=1LL*x*(x-)%mod*(x-)%mod*inv%mod;
int last;
for(int i=;i<=x;i=last+)
{
last=x/(x/i);
sum-=1LL*(last-i+)*calc(x/i);
while(sum<)sum+=mod;
}
return (mp[x]=sum);
} int main()
{
for(int i=;i<=MAXN;i++)
f[i]=1LL*(i-)*(i-)%mod;
for(int i=;i<=MAXN;i++)
for(int j=i<<;j<=MAXN;j+=i)
f[j]=(f[j]-f[i]+mod)%mod;
// for(int i=1;i<=10;i++)cout<<f[i]<<endl;
for(int i=;i<=MAXN;i++) f[i]=(f[i]+f[i-])%mod;
for(int t=read();t;t--)
printf("%lld\n",calc(read()));
return ;
}
[hdu5608]function的更多相关文章
- 通过百度echarts实现数据图表展示功能
现在我们在工作中,在开发中都会或多或少的用到图表统计数据显示给用户.通过图表可以很直观的,直接的将数据呈现出来.这里我就介绍说一下利用百度开源的echarts图表技术实现的具体功能. 1.对于不太理解 ...
- hdu5608:function
$n^2-3n+2=\sum_{d|i}f(i)$,问$f(i)$前$n$项和. 方法一:直接切入! $S(n)=\sum_{i=1}^{n}f(i)=\sum_{i=1}^{n}(i^2-3i+2- ...
- jsp中出现onclick函数提示Cannot return from outside a function or method
在使用Myeclipse10部署完项目后,原先不出错的项目,会有红色的叉叉,JSP页面会提示onclick函数错误 Cannot return from outside a function or m ...
- JavaScript function函数种类
本篇主要介绍普通函数.匿名函数.闭包函数 目录 1. 普通函数:介绍普通函数的特性:同名覆盖.arguments对象.默认返回值等. 2. 匿名函数:介绍匿名函数的特性:变量匿名函数.无名称匿名函数. ...
- 在ubuntu16.10 PHP测试连接MySQL中出现Call to undefined function: mysql_connect()
1.问题: 测试php7.0 链接mysql数据库的时候发生错误: Fatal error: Uncaught Error: Call to undefined function mysqli_con ...
- jquery中的$(document).ready(function() {});
当文档载入时执行function函数里的代码, 这部分代码主要声明,页面加载后 "监听事件" 的方法.例如: $(document).ready( $("a") ...
- Function.prototype.toString 的使用技巧
Function.prototype.toString这个原型方法可以帮助你获得函数的源代码, 比如: function hello ( msg ){ console.log("hello& ...
- 转:ORA-15186: ASMLIB error function = [asm_open], error = [1], 2009-05-24 13:57:38
转:ORA-15186: ASMLIB error function = [asm_open], error = [1], 2009-05-24 13:57:38http://space.itpub. ...
- [Xamarin] 透過Native Code呼叫 JavaScript function (转帖)
今天我們來聊聊關於如何使用WebView 中的Javascript 來呼叫 Native Code 的部分 首先,你得先來看看這篇[Xamarin] 使用Webview 來做APP因為這篇文章至少講解 ...
随机推荐
- 《高级软件测试》JIRA使用手册(一)JIRA基本情况
JIRA 官方网站为:https://www.atlassian.com/software/jira 中文代理网站为:https://www.jira.cn 现版本:v7.3.0 Atlassian公 ...
- NOIP2016 天天爱跑步 正解
暴力移步 http://www.cnblogs.com/TheRoadToTheGold/p/6673430.html 首先解决本题应用的知识点: dfs序——将求子树的信息(树形)转化为求一段连续区 ...
- C语言Linix服务器网络爬虫项目(二)项目设计和通过一个http请求抓取网页的简单实现
我们通过上一篇了解了爬虫具体要实现的工作之后,我们分析得出的网络爬虫的基本工作流程如下: 1.首先选取一部分精心挑选的种子URL: 2.将这些URL放入待抓取URL队列: 3.从待抓取URL队列中取出 ...
- 作业五:RE 模块模拟计算器
# !/usr/bin/env python3 # _*_coding:utf-8_*_ ''' 实现模拟计算器的功能: 公式: - * ( (- +(-/) * (-*/ + /*/* + * / ...
- ubuntu临时修改ip,mac的方法示例
ifconfig eth0 down ifconfig eth0 154.84.28.148 netmask 255.255.255.0 route add default gw 154.84.28. ...
- Android基础字符串String.md
问题抛出 String这个常量在我们代码中会经常被用到,那么我们了解 String stringbuffer StringBudilder三者之间的区别吗 问题解答 String 字符串常量,位于常量 ...
- winform中的数据绑定
1. 简单的数据绑定 例1 using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings[& ...
- 全球性WannaCry蠕虫勒索病毒感染前后应对措施
前言:针对WannaCrypt勒索病毒的讨论和技术文章是铺天盖地,大量的技术流派,安全厂家等纷纷献计献策,有安全厂家开发各种安全工具,对安全生态来说是一个好事,但对个人未必就是好事,我们国家很多用户是 ...
- javaIO流--Writer,Reader
Writer /** *<li> Writer中定义的一个重要的方法: * public void writer(String str)throws IOException; */ pac ...
- [LeetCode] Dota2 Senate 刀塔二参议院
In the world of Dota2, there are two parties: the Radiant and the Dire. The Dota2 senate consists of ...