栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

zoj 3881 From the ABC conjecture

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

zoj 3881 From the ABC conjecture

#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 ( "%dn" , dfs ( n ) ) ;    return 0 ;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/375011.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号