Sum of the Line

                                            5222: Sum of the Line

                                                                 时间限制: 1 Sec  内存限制: 128 MB
                                                                             提交: 147  解决: 37
                                                                [提交] [状态] [讨论版] [命题人:admin]

题目描述

Consider a triangle of integers, denoted by T. The value at (r, c) is denoted by Tr,c , where 1 ≤ r and 1 ≤ c ≤ r. If the greatest common divisor of r and c is exactly 1, Tr,c = c, or 0 otherwise.
Now, we have another triangle of integers, denoted by S. The value at (r, c) is denoted by S r,c , where 1 ≤ r and 1 ≤ c ≤ r. S r,c is defined as the summation   
Here comes your turn. For given positive integer k, you need to calculate the summation of elements in k-th row of the triangle S.

输入

The first line of input contains an integer t (1 ≤ t ≤ 10000) which is the number of test cases.
Each test case includes a single line with an integer k described as above satisfying 2 ≤ k ≤ 10^8 .

输出

For each case, calculate the summation of elements in the k-th row of S, and output the remainder when it divided
by 998244353.

样例输入

2
2
3

样例输出

1
5

当时做的时候想到了容斥嘛,可惜不会写好多个的,只写过3,4个元素的,这个一看太多就觉得可能想错了,

结果最后还是容斥。。

1素数线性筛选打个表,

2将当前数用唯一分解定理分解

3套用公式1*1+2*2+3*3+4*4+……+n*n = n*(n+1)*(2*n+1)/6

容易看出假设要去掉的是k,那么去掉的肯定是k和k的倍数

那么就是去掉k*k+(2k)*(2k)+……一共n/k个数

提出k*k就是k*k*(1*1+2*2+3*3……)

就是k*k*c*(c+1)*(2*c+1)/6(c=n/k)

 

#include<bits/stdc++.h>
#define ll long long
#define mod 998244353
using namespace std;
int vis[10011];
int prim[1229+3];
const int maxn = 1e4+7;
const ll Six = 166374059;
int cnt;
ll Getmod(ll a,ll b){return (a%mod*(b%mod))%mod;}
void Eulerprim()
{
    for(int i=2;i<maxn;i++)
    {
        if(!vis[i])
            prim[++cnt] = i;
        for(int j=1;j<=cnt&&prim[j]*i<maxn;j++)
        {
            vis[prim[j]*i] = 1;
            if(i%prim[j]==0)
                break;
        }
    }
}
void sovle()
{
    int prm[20],p_cnt = 0;
    ll n,tn;
    scanf("%lld",&n),tn=n;
    ll sum = Getmod( Getmod(n,n+1), Getmod(2LL*n+1,Six) );

    for(int i=1;i<=cnt;i++)
    {
        if(n<prim[i])break;
        if(n%prim[i]==0)
        {
            prm[p_cnt++] = prim[i];
            while(n%prim[i]==0)n/=prim[i];
        }
    }

    if(n>1)prm[p_cnt++] = n;

    ll ans = 0;

    for(int i = 1; i < (1<<p_cnt) ; i++)
    {
        int c = 0;
        ll x = 1;
        for(int j = 0;j<p_cnt;j++)
        {
            if(1&(i>>j))
            {
                x = x*prm[j] %mod;
                c++;
            }
        }
        n = tn/x;
        if(c&1)    ans = (ans + Getmod( Getmod( Getmod(x,x), Getmod(n,n+1) ), Getmod(2LL*n+1,Six) ) )%mod;
        else ans = (mod + ans - Getmod( Getmod( Getmod(x,x), Getmod(n,n+1) ), Getmod(2LL*n+1,Six) ) )%mod;
    }
    printf("%lld\n",((sum-ans)%mod+mod)%mod);
}

int main()
{
    Eulerprim();
    int t;
    scanf("%d",&t);
    while(t--)
        sovle();
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Jonathan is fighting against DIO's Vampire minions. There are n of them with strengths a1,a2,…,an. Denote (l,r) as the group consisting of the vampires with indices from l to r. Jonathan realizes that the strength of any such group is in its weakest link, that is, the bitwise AND. More formally, the strength level of the group (l,r) is defined as f(l,r)=al&al+1&al+2&…&ar. Here, & denotes the bitwise AND operation. Because Jonathan would like to defeat the vampire minions fast, he will divide the vampires into contiguous groups, such that each vampire is in exactly one group, and the sum of strengths of the groups is minimized. Among all ways to divide the vampires, he would like to find the way with the maximum number of groups. Given the strengths of each of the n vampires, find the maximum number of groups among all possible ways to divide the vampires with the smallest sum of strengths. Input The first line contains a single integer t (1≤t≤104) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer n (1≤n≤2⋅105) — the number of vampires. The second line of each test case contains n integers a1,a2,…,an (0≤ai≤109) — the individual strength of each vampire. The sum of n over all test cases does not exceed 2⋅105. Output For each test case, output a single integer — the maximum number of groups among all possible ways to divide the vampires with the smallest sum of strengths.c++实现
最新发布
07-07
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值