ZOJ3558 How Many Sets III(公式题)
转载请注明出处: 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:
- T is a subset of S
- Elements in T can form an arithmetic progression in some order.
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(公式题)的更多相关文章
- 华东交通大学2018年ACM“双基”程序设计竞赛 C. 公式题 (2) (矩阵快速幂)
题目链接:公式题 (2) 比赛链接:华东交通大学2018年ACM"双基"程序设计竞赛 题目描述 令f(n)=2f(n-1)+3f(n-2)+n,f(1)=1,f(2)=2 令g(n ...
- 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 ...
- 牛客网 牛客小白月赛1 E.圆与三角形-公式题
E.圆与三角形 链接:https://www.nowcoder.com/acm/contest/85/E来源:牛客网 这个题把公式推一下, 发现就是1+sinA*r,sinA最大为1,所以 ...
- codeforces 340C Tourist Problem(公式题)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud Tourist Problem Iahub is a big fan of tou ...
- 89. Gray Code(公式题)
The gray code is a binary numeral system where two successive values differ in only one bit. Given a ...
- codeforces GYM 100971F 公式题或者三分
F. Two Points time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- LightOJ 1248 Dice (III) (水题,期望DP)
题意:给出一个n面的色子,问看到每个面的投掷次数期望是多少. 析:这个题很水啊,就是他解释样例解释的太...我鄙视他,,,,, dp[i] 表示 已经看到 i 面的期望是多少,然后两种选择一种是看到新 ...
- 计蒜客 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 ...
- 【BZOJ1426】收集邮票 概率DP 论文题 推公式题
链接: #include <stdio.h> int main() { puts("转载请注明出处[辗转山河弋流歌 by 空灰冰魂]谢谢"); puts("网 ...
随机推荐
- 基于verilog的FPGA编程经验总结(XILINX ISE工具)
1.用ISE仿真的时候.所用变量一定要初始化. ISE默认初始量为"XXXXX", 而Quarters是默认为"00000"的, 其实实际上, 下到FPGA里后 ...
- Boost 和 STL 相比有哪些优势和劣势?
1. 在设计原则上,STL和Boost大体统一因为STL和Boost基本上都是标准委员会那批人在策划.审核和维护,所以口味上是相对接近的.但是因为Boost并不在标准中,或者说是下一代标准的试验场,所 ...
- 2015第24周五Spring的AOP
AOP(面向方面编程:Aspect Oriented Programing)和IoC一样是Spring容器的内核,声明式事务的功能在此基础上开花结果.但AOP的应用场合是受限的,它一般只适合于那些具有 ...
- Java[3] Java多线程相关资料
Java多线程: http://www.uml.org.cn/j2ee/201509093.asp
- appium 并发测试
Android并发测试 Appium提供了在一台设备上启动多个Android会话的方案,而这个方案需要你输入不同的指令来启动多个Appium服务来实现. 启动多个Android会话的重要指令包括: - ...
- jquery绑定事件on的用法
语法 $(selector).on(event,childSelector,data,function,map) 参数 描述 event 必需.规定要从被选元素移除的一个或多个事件或命名空间.由空格分 ...
- StoryBoard 设置TabBar SelectImage 和tintColor
如图:StoryBoard 结构是 Tabbar + Navi + ViewController 需求:需要修改TabBar的Image 和SelectImage 设置Image 设置SelectIm ...
- (转)ObjC利用正则表达式抓取网页内容(网络爬虫)
转自:http://www.cocoachina.com/bbs/read.php?tid=103813 *****boy]原创 2012年5月20日 在开发项目的过程,很多情况下我们需要利用互联网上 ...
- 高性能 Socket 组件 HP-Socket v3.2.1-RC4 公布
HP-Socket 是一套通用的高性能 TCP/UDP Socket 组件,包括服务端组件.client组件和 Agent 组件,广泛适用于各种不同应用场景的 TCP/UDP 通信系统,提供 C/C+ ...
- google在线測试练习题1
Problem You receive a credit C at a local store and would like to buy two items. You first walk thro ...