2018沈阳网络赛G

容斥+状压

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
#include<vector>
//const int MAX = 110;
const int N = 100000;
int arr[6000000];//p[N]用来存质数
ll n;
int p;
vector<ll>v;
void getp(ll m, ll n) {  //分解质因子
    p = 0;
    for(int i = 2; i <= n && i * i <= m; i++) {
        if(m % i == 0) {
            arr[p++] = i;
            while(m % i == 0)
                m /= i;
        }
    }
    if(m > 1) arr[p++] = m;
}
ll get(ll temp)
{
        ll sum_temp;
        sum_temp=1ll*(((1+n/temp)*(n/temp)/2)%MOD)*temp%MOD;
        sum_temp += 1ll*((((((n/temp)*((n/temp)+1)%MOD)*(2*(n/temp)+1))%MOD)*166666668)%MOD)*temp*temp%MOD;
        sum_temp=1ll*sum_temp%MOD;
        return sum_temp;
}

int main(){
    ll  m;
    while(scanf("%lld %lld", &n, &m) != EOF)
    {
        ll sum = 0;
        sum = 1ll*((n+1)*n/2)%MOD;
        sum += 1ll*((((n*(n+1)%MOD)*(2*n+1))%MOD)*166666668)%MOD;
        sum= 1ll*sum%MOD;
        getp(m, n);
    //    cout<<p<<" "<<sum<<endl;
        ll ans = 0;
        for(int i = 1; i < (1 << p); i++) { //状压
            ll res = 0, cnt = 1;
            for(int j = 0; j < p; j++) {
                if(i & (1 << j)) {
                    cnt *= arr[j];
                    res++;
                }
            }
            if(res & 1) ans += get(cnt); //容斥
            else ans -= get(cnt);
            ans = (ans + MOD)%MOD;
        //    cout<<ans<<endl;
        }
        sum = (sum - ans + MOD)%MOD;
        printf("%lld\n",sum );
    }
    return 0;
}

原文地址:https://www.cnblogs.com/LMissher/p/9610856.html

时间: 2024-11-06 12:50:32

2018沈阳网络赛G的相关文章

[ACM-ICPC 2018 沈阳网络赛] G. Spare Tire (思维+容斥)

A sequence of integer \lbrace a_n \rbrace{an?} can be expressed as: \displaystyle a_n = \left\{ \begin{array}{lr} 0, & n=0\\ 2, & n=1\\ \frac{3a_{n-1}-a_{n-2}}{2}+n+1, & n>1 \end{array} \right.an?=????0,2,23an−1?−an−2??+n+1,?n=0n=1n>1? N

[ACM-ICPC 2018 沈阳网络赛] Ka Chang (dfs序+树状数组+分块)

Given a rooted tree ( the root is node 11 ) of NN nodes. Initially, each node has zero point. Then, you need to handle QQ operations. There're two types: 1\ L\ X1 L X: Increase points by XX of all nodes whose depth equals LL ( the depth of the root i

2018沈阳网络赛J

给一颗树,两种操作,一种把同一层的点权值加上v,另一种求一点下的子树权值和. 按层数中点个数分块,小块直接暴力把所有点用bit更新,大块把层的值存下来. 询问的时候子树权值和为bit中的值以及其下面的点在大块中的值,下面中的点在大块中的值用二分实现. #include <bits/stdc++.h> #include <unordered_set> #include <unordered_map> #define pb push_back #define mp make

2015沈阳网络赛1003 Minimum Cut 树链剖分 数组维护前缀和进行区间增减

2015沈阳网络赛1003  Minimum Cut   树链剖分 数组维护前缀和进行区间增减 Minimum Cut Time Limit: 3000/2000 MS (Java/Others)    Memory Limit: 65535/102400 K (Java/Others)Total Submission(s): 0    Accepted Submission(s): 0 Problem Description Given a simple unweighted graph G 

2018 CCPC网络赛

2018 CCPC网络赛 Buy and Resell 题目描述:有一种物品,在\(n\)个地点的价格为\(a_i\),现在一次经过这\(n\)个地点,在每个地点可以买一个这样的物品,也可以卖出一个物品,问最终赚的钱的最大值. solution 用两个堆来维护,一个堆维护已经找到卖家的,一个堆维护还没找到卖家的. 对于第\(i\)个地点,在已经找到卖家的堆里找出卖的钱的最小值,如果最小值小于\(a_i\),则将卖家换成\(i\),然后将原来的卖家放到没找到卖家的那里:如果最小值对于\(a_i\)

2018徐州网络赛H. Ryuji doesn&#39;t want to study

题目链接: https://nanti.jisuanke.com/t/31458 题解: 建立两个树状数组,第一个是,a[1]*n+a[2]*(n-1)....+a[n]*1;第二个是正常的a[1],a[2],a[3]...a[n] #include "bits/stdc++.h" using namespace std; #define ll long long const int MAXN=1e5+10; ll sum[MAXN],ans[MAXN]; ll num[MAXN];

ACM-ICPC 2018徐州网络赛-H题 Ryuji doesn&#39;t want to study

C*M....死于update的一个long long写成int了 心累 不想写过程了 ******** 树状数组,一个平的一个斜着的,怎么斜都行 题库链接:https://nanti.jisuanke.com/t/31460 #include <iostream> #include <cstring> #define ll long long #define lowbit(x) (x & -x) using namespace std; const int maxn =

2019ACM-ICPC沈阳网络赛-C-Dawn-K&#39;s water(完全背包模板题)

Dawn-K's water  1000ms 262144K Dawn-K recently discovered a very magical phenomenon in the supermarket of Northeastern University: The large package is not necessarily more expensive than the small package. On this day, Dawn-K came to the supermarket

2019ACM-ICPC沈阳网络赛-K-Guanguan&#39;s Happy water(思维+暴力)

Guanguan's Happy water 4000ms 262144K Rather than drinking happy water, Guanguan loves storing happy water. So he bought a refrigerator and stored a_iai? bottles of cola into it every day. When the storage is finished on the kk-th day, the refrigerat