转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud

How Many Sets III


Time Limit: 2 Seconds      Memory Limit: 65536 KB

Given a set S = {1, 2, ..., n}, your job is to count how many set T satisfies the following condition:

Input

There are multiple cases, each contains only one integer n ( 1 ≤ n ≤ 109 ) in one line, process to the end of file.

Output

For each case, output an integer in a single line: the total number of set T that meets the requirmentin the description above, for the answer may be too large, just output it mod 100000007.

Sample Input

2
3

Sample Output

1
4

看到这种输出只和一个数有关的,而且还是整数,想都不想,先暴力求出前几项,然后oeis大法,查到公式后

a(n) = sum { i=1..n-1, j=1..floor((n-1)/i) } (n - i*j)

发现这个公式只是n^2的,于是我们需要优化其中的步骤,首先,对于第二维,我们很容易搞掉,那么对于第一维,我们发现其中有一个(n-1)/i,那么其实有很多是对应的,于是我们只需要枚举1到sqrt(n-1)即可。即对于每一个i,在公差在(n-1)/(i+1) + 1到(n-1)/i这个范围内是可求的,另外注意求一下其相对的情况,看上去比较轻松,然而我这种数学渣还是推了半个多小时才推出来的

 /**
* code generated by JHelper
* More info: https://github.com/AlexeyDmitriev/JHelper
* @author xyiyy @https://github.com/xyiyy
*/ #include <iostream>
#include <fstream> //#####################
//Author:fraud
//Blog: http://www.cnblogs.com/fraud/
//#####################
//#pragma comment(linker, "/STACK:102400000,102400000")
#include <iostream>
#include <sstream>
#include <ios>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <vector>
#include <string>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <cctype> using namespace std;
typedef long long ll; //
// Created by xyiyy on 2015/8/5.
// #ifndef ICPC_INV_HPP
#define ICPC_INV_HPP
typedef long long ll; void extgcd(ll a, ll b, ll &d, ll &x, ll &y) {
if (!b) {
d = a;
x = ;
y = ;
}
else {
extgcd(b, a % b, d, y, x);
y -= x * (a / b);
}
} ll inv(ll a, ll mod) {
ll x, y, d;
extgcd(a, mod, d, x, y);
return d == ? (x % mod + mod) % mod : -;
} #endif //ICPC_INV_HPP const ll mod = ; class TaskJ {
public:
void solve(std::istream &in, std::ostream &out) {
ll n;
while (in >> n) {
ll ans = ;
ll m = n - ;
ll num = inv(, mod);
for (ll i = ; i * i <= m; i++) {
ll r = m / i;
ll l = m / (i + ) + ;
if (l > r)continue;
ans += (n * i % mod * (r - l + ) % mod -
(1LL + i) * i % mod * num % mod * (l + r) % mod * (r - l + ) % mod * num % mod) % mod + mod;
ans %= mod;
if (i != r)ans += (n * r % mod - i * r % mod * (1LL + r) % mod * num % mod) % mod + mod;
ans %= mod;
}
out << ans << endl;
}
}
}; int main() {
std::ios::sync_with_stdio(false);
std::cin.tie();
TaskJ solver;
std::istream &in(std::cin);
std::ostream &out(std::cout);
solver.solve(in, out);
return ;
}

ZOJ3558 How Many Sets III(公式题)的更多相关文章

  1. 华东交通大学2018年ACM“双基”程序设计竞赛 C. 公式题 (2) (矩阵快速幂)

    题目链接:公式题 (2) 比赛链接:华东交通大学2018年ACM"双基"程序设计竞赛 题目描述 令f(n)=2f(n-1)+3f(n-2)+n,f(1)=1,f(2)=2 令g(n ...

  2. HDU 4762 Cut the Cake (2013长春网络赛1004题,公式题)

    Cut the Cake Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  3. 牛客网 牛客小白月赛1 E.圆与三角形-公式题

    E.圆与三角形   链接:https://www.nowcoder.com/acm/contest/85/E来源:牛客网     这个题把公式推一下, 发现就是1+sinA*r,sinA最大为1,所以 ...

  4. codeforces 340C Tourist Problem(公式题)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Tourist Problem Iahub is a big fan of tou ...

  5. 89. Gray Code(公式题)

    The gray code is a binary numeral system where two successive values differ in only one bit. Given a ...

  6. codeforces GYM 100971F 公式题或者三分

    F. Two Points time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  7. LightOJ 1248 Dice (III) (水题,期望DP)

    题意:给出一个n面的色子,问看到每个面的投掷次数期望是多少. 析:这个题很水啊,就是他解释样例解释的太...我鄙视他,,,,, dp[i] 表示 已经看到 i 面的期望是多少,然后两种选择一种是看到新 ...

  8. 计蒜客 30990.An Olympian Math Problem-数学公式题 (ACM-ICPC 2018 南京赛区网络预赛 A)

    A. An Olympian Math Problem 54.28% 1000ms 65536K   Alice, a student of grade 66, is thinking about a ...

  9. 【BZOJ1426】收集邮票 概率DP 论文题 推公式题

    链接: #include <stdio.h> int main() { puts("转载请注明出处[辗转山河弋流歌 by 空灰冰魂]谢谢"); puts("网 ...

随机推荐

  1. Symfony2目录结构说明

    了解框架的目录结构是框架快速入门的一个途径,一个成熟的框架,每个功能模块都被划分存放在不同的目录. Symfony2一级目录结构: ├── app //这目录下包含了,配置文件(应用的配置文件会被im ...

  2. bat判断某个目录是否存在

    使用批处理判断某个目录是否存在的语句. if not exist xxx_folder_name md xxx_folder_name

  3. shell脚本实现仅保留某目录下最新的两个文件

    #!/bin/sh export DS_DIR=/home/cxy/test if [ ! -d $DS_DIR ]; then mkdir $DS_DIR else echo "$DS_D ...

  4. myEclipse8.* 手动安装ADT插件[转]

    Myeclipse8.6手动添加插件: 自动在线安装完ADT插件会导致myeclipse8.6中无法创建web项目以及其他项.解决方法是手动安装步骤如下: 首先安装好 MyEclipse 8.6. 1 ...

  5. VMProtect修复导入表的插件

    壳版本:VMProtect.Ultimate.2.12.3 样本:TKLobby.exe 目的:IAT修复 作者:MrWrong 标题:VMProtect修复导入表的插件 只是感兴趣,没有其他目的.失 ...

  6. Dedecms v5.7包含上传漏洞利用

    Title:Dedecms v5.7包含上传漏洞利用 --2012-09-21 10:16 注册,登录,免邮箱验证. up.htm ---------------------------------- ...

  7. target vs currentTarget, clientWidth vs offsetWidth

    width: document < window(browser) < screen document--> clientWidth < offsetWidth(include ...

  8. 用Doxygen生成文档

    我是生成C/C++的文档,输出html格式的文档.就不做成CHM了. 注释要这种写:(当然,有数种注释风格,选择任意你喜欢的就行) /** * * 一系列的doxygen的 command * * * ...

  9. 【HDOJ】1494 跑跑卡丁车

    DP,将能量映射为0~14,注意当选择这圈加速的时候,这圈就不能再储存能量,同时能量14可能转化为10. #include <cstdio> #include <cstring> ...

  10. unix网络编程之简介

    通常客户一次只与一个服务器通信, 上图为:一个服务器同时处理多个客户的请求. 上图为:客户与服务器使用TCP协议在同一个以太网中通信. 路由器是广域网的架构设备.今天,最大的广域网是因特网. 上图为: ...