容斥原理 学习 M - Calculation 2 HDU - 3501

https://vjudge.net/contest/177165#rank
欢迎来刷我抄的专题.

因为数不大,很快就想到了质因数分解,然后容斥原理做一遍,但是取余的地方没细心.爆long long 却一直没发现.卡了很久.

思路大抵就是 : 质因数分解, 算每一个质因数的贡献,但我们平常所减的是求个数的,这里求完了个数后转变成和其实也蛮简单的, 我们这样考虑 1 - (n-1)中有a个p质因数的倍数, 那么这个质因数的贡献就是p*sum(1+2+..+a), 然后容斥消去重复 的就行了.

#include<cstdio>
#include<iostream>
#include<bitset>
#include<cstring>
#define ll long long
const int maxn = 5e5;
using namespace std;
const int mod = 1000000007;
bitset<maxn> judge;
int prime[maxn];

int tot = 0;
ll l,r,n;
ll co[maxn];
void init(){
    judge.reset();
    tot = 0;
    for(int i = 2; i < maxn ; i++){
        if(!judge[i]){
            prime[tot++] = i;
        }
        for(int j = 0; j < tot ;j++){
            if(i*prime[j] >= maxn)break;
            judge[i*prime[j]] = 1;
            if(i%prime[j] == 0){
                break;
            }
        }
    }
}

ll sum(ll n){
    if(n%2==0){
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
The Cortex-M0 processor does not have a hardware divider, which means that division calculations are performed using software routines. There are various algorithms for performing software division, but one commonly used method is called "long division". In long division, the divisor is repeatedly subtracted from the dividend until the remainder is less than the divisor. The number of times the divisor is subtracted is the quotient, and the remainder is the final result. This process is repeated until all digits of the dividend have been processed. Here is a sample code for performing integer division on Cortex-M0 using long division: ``` int divide(int dividend, int divisor) { int quotient = 0, remainder = 0; int sign = ((dividend < 0) ^ (divisor < 0)) ? -1 : 1; // convert both operands to positive if (dividend < 0) dividend = -dividend; if (divisor < 0) divisor = -divisor; // perform long division for (int i = 31; i >= 0; i--) { remainder <<= 1; // left shift remainder remainder |= (dividend >> i) & 1; // add next bit from dividend to remainder if (remainder >= divisor) { remainder -= divisor; quotient |= (1 << i); // set corresponding bit in quotient } } // apply sign quotient = sign * quotient; return quotient; } ``` Note that this code assumes that both the dividend and divisor are 32-bit integers. It also handles negative operands correctly and applies the correct sign to the result. However, it may not be the most efficient implementation and may need to be optimized for specific use cases.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值