【ZOJ】3881 From the ABC conjecture【暴力容斥】
来源:互联网 发布:资本运作软件 编辑:程序博客网 时间:2024/05/22 08:27
传送门:【ZOJ】3881 From the ABC conjecture
复杂度大概
暴力展开发现贡献为:
然后是一个暴力dfs容斥的过程:
可以发现右边是一个原式的递归式,于是我们可以暴力枚举
#include <stdio.h>#include <string.h>#include <map>#include <algorithm>using namespace std ;typedef long long LL ;#define clr( a , x ) memset ( a , x , sizeof a )const int MAXN = 20000005 ;const int mod = 1e9 + 9 ;const int v2 = 5e8 + 5 ;map < LL , int > mp ;map < LL , int > :: iterator it ;bool vis[MAXN] ;int dp[MAXN] ;LL n ;int dfs ( LL n , LL ans = 0 ) { for ( LL i = 1 , j ; i <= n ; i = j + 1 ) { j = min ( n , n / ( n / i ) ) ; LL ni = n / i , x = i + j , y = j - i + 1 ; if ( ni >= mod ) ni %= mod ; if ( x >= mod ) x %= mod ; if ( y >= mod ) y %= mod ; ans += ni * x % mod * y % mod * v2 % mod ; } for ( LL i = 2 ; i * i <= n ; ++ i ) { LL x = n / ( i * i ) ; if ( x < MAXN ) { if ( !vis[x] ) { vis[x] = true ; dp[x] = dfs ( x ) ; } ans -= dp[x] * i % mod ; } else { it = mp.find ( x ) ; if ( it != mp.end () ) ans -= it->second * i % mod ; else { int tmp = dfs ( x ) ; mp.insert ( map < LL , int > :: value_type ( x , tmp ) ) ; ans -= tmp * i % mod ; } } } return ( ans % mod + mod ) % mod ;}int main () { while ( ~scanf ( "%lld" , &n ) ) printf ( "%d\n" , dfs ( n ) ) ; return 0 ;}
0 0
- 【ZOJ】3881 From the ABC conjecture【暴力容斥】
- ZOJ 3881 From the ABC conjecture
- ZOJ3881:From the ABC conjecture(莫比乌斯反演)
- Zoj 3616 Choir III 【有想法的暴力】【容斥】
- ZOJ - 3809 The Himalayas 暴力
- ZOJ 3547 《The Boss on Mars》(容斥定理)
- zoj 3547 - The Boss on Mars(容斥原理)
- ZOJ 3547 The Boss on Mars(容斥)
- ZOJ 3547 - The Boss on Mars(容斥)
- ZOJ 3547 The Boss on Mars(容斥)
- ZOJ 3465 The Hive 暴力模拟
- zoj 1610 Count the Colors【暴力乱搞】
- zoj 1610 Count the Colors 【暴力】
- ZOJ 3752The Three Guys(暴力)
- ZOJ-3752-The Three Guys【暴力】
- ZOJ 3939The Lucky Week<模拟/暴力>
- Escape from the Hell(暴力瞎搞)
- ZOJ 2836 容斥原理
- myclipse web项目 eclipse中不能运行
- FPGA开发
- sql:除非另外还指定了 TOP 或 FOR XML,否则,ORDER BY 子句在视图、内联函数、派生表、子查询
- dm8127/8148下如何进行dsplink的编写
- [LeetCode] Combinations
- 【ZOJ】3881 From the ABC conjecture【暴力容斥】
- C++基础:动态链接库调用方法总结
- 使用 Rails 的 custom configuration 来配置 Redis
- 打印水仙花
- 简单的 jquery控制表单提交
- 解决爆栈,手动加栈!
- 常用的JDBC驱动名字和URL列表
- P/Invoke and Marshaling
- hive与hbase整合过程