Gcd(莫比乌斯反演)

题解:YY的GCD 【莫比乌斯反演】 题意 求∑i=1n∑j=im[gcd(i,j)==k](k∈prima)求\sum_{i=1}^n\sum_{j=i}^m [ gcd(i,j)==k ](k\in{prima})求i=1∑n​j=i∑m​[gcd(i,j)==k](k∈prima) 根据莫比乌斯反演的常见套路,我们可以很容易地化到这一步: ∑k∈prima∑d=1min(n,m)μ(d)⌊nkd⌋⌊mkd⌋\sum_{k\in{... 阅读详情

Gcd

给定整数N,求1<=x,y<=N且Gcd(x,y)为素数的
数对(x,y)有多少对.

Input

一个整数N

Output

如题

Sample Input
4

Sample Output
4
Hint

hint

对于样例(2,2),(2,4),(3,3),(4,2)

1<=N<=10^7
题意:

略

分析:

和这道题完全一样
只不过不需要优化直接两重for循环枚举素数即可

code:

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAXN = 1e7+10;
typedef long long LL;

//LL F[MAXN],f[MAXN];
LL pri[MAXN],pri_num;
LL mu[MAXN];//莫比乌斯函数值
bool vis[MAXN];

void mobius(int N)  //筛法求莫比乌斯函数
{
    pri_num = 0;//素数个数
    memset(vis, false, sizeof(vis));
    vis[1] = true;
    mu[1] = 1;
    for(int i = 2; i <=N; i++)
    {
        if(!vis[i])
        {
            pri[pri_num++] = i;
            mu[i] = -1;
        }
        for(int j=0; j<pri_num && i*pri[j]<N ; j++)
        {
            vis[i*pri[j]]=true;//标记非素数
            //eg:i=3,i%2,mu[3*2]=-mu[3]=1;----;i=6,i%5,mu[6*5]=-mu[6]=-1;
            if(i%pri[j])mu[i*pri[j]] = -mu[i];
            else
            {
                mu[i*pri[j]] = 0;
                break;
            }

        }
    }
}

int main()
{
//    freopen("in.txt","r",stdin);
//    freopen("out.txt","w",stdout);
    LL n;
    mobius(10000000);
    while(~scanf("%lld",&n))
    {
        LL ans = (LL)0;
        for(LL i=0; pri[i]<=n; i++)
        {
            for(LL j=1; j<=n/pri[i]; j++)
                ans+=(LL)(mu[j]*((n/pri[i])/j)*((n/pri[i])/j));
        }
        printf("%lld\n",ans);
    }
    return 0;
}
【bzoj2820】YY的GCD 莫比乌斯反演 Description神犇YY虐完数论后给傻×kAc出了一题 给定N, M,求1<=x<=N, 1<=y<=M且gcd(x, y)为质数的(x, y)有多少对 kAc这种傻×必然不会了,于是向你来请教…… 多组输入Input第一行一个整数T 表述数据组数 接下来T行,每行两个正整数,表示N, MOutputT行,每行一个整数表示第i组数据的结果Sample Input210 10100 10 阅读详情

相关推荐

探索LLM世界:新手小白的学习路线图

通过系统的学习和实践,新手小白也能逐步掌握LLM的核心技术。掌握LLM不仅能提升个人技术水平,还能为职业发展带来广阔的前景。未来,随着技术的不断进步,LLM将在更多领域发挥重要作用,成为推动科技进步的重要力量。学习LLM是一条充满挑战但也充满机遇的道路。只要你坚持不懈、不断学习和实践,就一定能够在LLM领域取得突破。希望本文提供的学习路线图能为你指明方向,助你早日掌握LLM,开启AI学习的新篇章!

m0_62110645的博客 2360

BZOJ 2818: 欧拉筛法求gcd(x,y)==k(k为素数)详解

给定整数N,求1&lt;=x,y&lt;=N且Gcd(x,y)为素数的  数对(x,y)有多少对. gcd(x,y)=p gcd(x/p,y/p)=1 枚举每个素数p,计算1~n/p中有多少对互质的数 表示1~i中有多少个与i互质的数,即phi(i) g[i]表示f[i]的前缀和 ans=2*∑g[n/p]-cnt tot是n以内素数的个数 #include&lt;cstdio&gt; #i...

qq_41668093的博客 771

FPGA实战:从零构建eMMC控制器(Verilog篇)

本文详细介绍了如何使用Verilog从零构建FPGA上的eMMC控制器,涵盖eMMC接口基础、命令系统解析、关键模块设计及性能优化技巧。通过实战案例,帮助开发者掌握高速数据存储解决方案,提升嵌入式系统开发能力。

weixin_26802933的博客 297

GCD(洛谷 2568)

题目描述 给定整数N,求1<=x,y<=N且Gcd(x,y)为素数的数对(x,y)有多少对. 输入格式 一个整数N 输出格式 答案 输入输出样例 输入 #1 4 输出 #1 4 说明/提示 对于样例(2,2),(2,4),(3,3),(4,2) 1<=N<=10^7 由题意得:gcd(x,y)=p(这里我们假设p为一个已知的质数)...

anglanjing7414的博客 637

CASIA数据集解析:图像篡改检测的黄金标准与实践指南

本文深入解析了CASIA数据集在图像篡改检测领域的核心价值与应用实践。作为中科院自动化所打造的黄金标准,CASIA数据集通过模拟真实篡改场景(如拼接和复制移动)为研究者提供全面支持。文章详细对比了v1.0与v2.0版本差异,分享数据预处理和模型训练的最佳实践,并探讨了未来研究方向,是图像篡改检测领域的重要参考指南。

kappa的博客 784

YOLOv8进阶:SEAM注意力与Repulsion Loss双剑合璧,突破遮挡检测瓶颈

做目标检测时,最头疼的莫过于目标被遮挡的场景——行人被树木挡住一半、车辆被广告牌遮挡部分轮廓……这些情况往往让模型“犯迷糊”。但现在,有了SEAM注意力模块和Repulsion Loss排斥损失,我们就能让YOLOv8在遮挡场景下也能“拨开迷雾见真章”。这篇教程会带你一步步理解这两个技术,并亲手把它们融入YOLOv8,让你的检测模型在复杂场景下也能稳如泰山。

FJN110的博客 233

GCD(莫比乌斯反演(数论公式+结论+因子个数)

这道题是真的好题!!!!我也是头一次搞莫比乌斯反演,没想到那么有用,但是的确对于它的理解是很有难度的!!! 题的意思很简单就是求在[a,b]区间取出的x和[c,d]区间取出的y使得gcd(x,y)==k的对数(注意这里的<x,y>为序偶(也就是有顺序)); 当时我拿着这个题,一脸的懵逼,QAQ; 然后百度了一下说是莫比乌斯反演;那什么是莫比乌斯反演呢? 其实我感觉如果要去证明是很难看...

qq_44555205的博客 1183

数据库小技能:数据导入脚本

背景:版本大升级,从2.0升级到3.0 ,服务端开发语言从c#换到java语言。数据库类型从microsalft sql server 换到mysql。数据来源于微信,用于查询卡bin。

专注于计算机研发知识和资讯分享 773

GCD【洛谷P2568】(小左的GCD)

题目描述 给定整数N,求1<=x,y<=N且Gcd(x,y)为素数的数对(x,y)有多少对. 输入格式 一个整数N 输出格式 答案 输入输出样例 输入 #1 复制 4 输出 #1 复制 4 说明/提示 对于样例(2,2),(2,4),(3,3),(4,2) 1<=N<=10^7 思路 对于质数p,满足gcd(i,j)=p的(i,j): p|i且 p|j,则设i=a,j=b。...

ESTHERWXY的博客 379

Java接入DeepSeek大模型:从零实现流式对话+多轮会话管理(完整项目实战)

emitter.completeWithError(new RuntimeException("连接DeepSeek服务超时"));private static final Set<String> BLACK_WORDS = Set.of("暴力", "色情", "政治敏感");emitter.onCompletion(() -> log.info("SSE连接完成"));emitter.onTimeout(() -> log.warn("SSE连接超时"));// 每个路由基础连接数。

wjianwei666的专栏 926

寻路最终版哦

相信大家用unity3d寻路的时候,一定会碰到多人

yxriyin的专栏 6953

gcd求和问题(莫比乌斯反演)

easy 1、设, 2、那么有,通过枚举可以将式子 化简到 3、通过莫比乌斯反演,可以得到,将化掉得到式子 做到这里复杂度是,对于次询问足够了,但是有些题就是询问次数超级多(比如 BZOJ 2301) 4、所以 ...

JZK-Keven 的博客 1600

论文复现5:UMI Universal Manipulation Interface

UMI 采用手持式夹具,加上精心的界面设计,可实现便携式、低成本和信息丰富的数据收集,以进行具有挑战性的双手和动态操作演示。配备这些功能后,UMI 框架解锁了新的机器人操作功能,只需更改每个任务的训练数据,即可实现零样本可推广的动态、双手、精确和长视野行为。我们通过全面的现实世界实验展示了 UMI 的多功能性和有效性,其中通过 UMI Zeroshot 学习的策略在对不同的人类演示进行训练时可以推广到新的环境和对象。项目主页:https://umi-gripper.github.io/

github_38060285的博客 1972

GCD(莫比乌斯反演)

GCD 莫比乌斯反演入门题目:题解 #include<iostream> #include<cstdio> #include<climits> #include<algorithm> #include<cstring> using namespace std; const int maxn=100005; int T,a,b,c,d...

天真有邪的博客 710

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

HDU 1695 GCD 莫比乌斯反演

题意: 求【1,b】和【1,d】两个区间内gcd为k的数对的数量,其中(x,y)和(y,x)看作同一数对。 题解: 莫比乌斯反演入门题。 基本套路,设f(k)和g(k),g(k)很容易求,再通过莫比乌斯反演求f(k)。 我的另一篇博客中莫比乌斯反演的过程与这道题类似,且已经写得很详细了。 最后可得式子(方便起见,不妨令b<=d,不满足则交换两者值,显然不影响结果) 线性筛预...

qq_38515845的博客 280

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

GCD (HDU-1695)(莫比乌斯反演)

Given 5 integers: a, b, c, d, k, you're to find x in a...b, y in c...d that GCD(x, y) = k. GCD(x, y) means the greatest common divisor of x and y. Since the number of choices may be very large, you're...

菜鸡的博客 548

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

洛谷 P2257 YY的GCD 莫比乌斯反演

P2257 YY的GCD 学习数论之莫比乌斯反演、杜教筛推荐:peng-ym 推理: 令:                                                                                             我们要求的是:                                                ...

ccsu_cat 380

hdu GCD(莫比乌斯反演+一点学习笔记)

GCD Time Limit: 6000/3000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 15999Accepted Submission(s): 6152 Problem Description Given 5 integers: a, b, c, d...

sher杨的博客 883

『莫比乌斯反演』YY的GCD

题目描述 给定N, M,求1<=x<=N, 1<=y<=M且gcd(x, y)为质数的(x, y)有多少对。 其中数据加强,N和M将近1000w。 题解 根据莫比乌斯反演公式,则一定有: f(i) = ∑d=1⌊ni⌋ g(i∗d)&ThickSpace;⟺&ThickSpace;g(i) = ∑d=1⌊ni...

Ronaldo7_ZYB的博客 506

GCD HDU - 1695(莫比乌斯反演入门题)

思路:最基本的gcd的莫比乌斯反演推式子,突然感觉gcd的好像都差不多。 还是很难将反演的两个式子灵活运用。 推式子先留个坑,以后补。 #include<cstdio> #include<cmath> #include<algorithm> #include<cstring> #include<string> #includ...

liexss的博客 305

P2257 YY的GCD(莫比乌斯反演入门)

题目链接 题意:求 sumi=1n∑j=1m[gcd(i,j)==prime]sum_{i=1}^{n} \sum_{j=1}^{m} [gcd(i,j) == prime]sumi=1n​∑j=1m​[gcd(i,j)==prime] 思路: 设 f(d)f(d)f(d) 为 gcd(x,y)==dgcd(x,y) == dgcd(x,y)==d 的个数, F(n)F(n)F(n) 为 gcd(x,y)==ngcd(x,y) == ngcd(x,y)==n 和 nnn 的倍数的个数 ( x∈[1,n]x

CCSU_GCR的博客 204

HDU1695 GCD(莫比乌斯反演)

传送门 看了1个多小时,终于懂了一点了 题目大意:给n,m,k.求gcd(x,y) = k(1<=x<=n, 1<=y<=m)的个数 思路:令F(i)表示i|gcd(x,y)的(x,y)的对数,显然F(x)=[nx]∗[mx]F(x)=[\frac{n}{x}]*[\frac{m}{x}]。 设f(x)为gcd(x,y)=x的对数。 因为F(x)=∑i|xf(i)F(x)=\sum_{i|

geng4512的专栏 1208

HDU 1695 GCD(莫比乌斯反演)

GCD Time limit3000 ms Memory limit32768 kB Given 5 integers: a, b, c, d, k, you’re to find x in a…b, y in c…d that GCD(x, y) = k. GCD(x, y) means the greatest common divisor of x and y. Since the numb...

Tan_JX 165

HDU1695——GCD(莫比乌斯反演)

三个启发性连接: http://blog.youkuaiyun.com/lixuepeng_001/article/details/50577932 http://www.cnblogs.com/femsub/p/5723780.html http://blog.youkuaiyun.com/acdreamers/article/details/8542292 GCD Time Limit:

我在浪里 753

Gcd HYSBZ - 2818 (莫比乌斯反演)

Gcd \[ Time Limit: 10000 ms\quad Memory Limit: 262144 kB \] 题意 求 \(gcd\left(x,y\right) = p\) 的对数,其中\(1 \leq x,y \leq n\)且 \(p\)是质数 思路 \(g\left(x\right)\) 表示 \(gcd\left(a, b\right) | x\) 的对数 \(f\l...

weixin_30262255的博客 154

HYSBZ 2818 (GCD)莫比乌斯反演

gcd 莫比乌斯反演 素数 欧拉函数 HYSBZ 2818

overload1997 668
上一篇: Mophues(莫比乌斯反演+分段)
下一篇: Find Integer HDU - 6441(费马大定理+勾股数)
Guuuuuu老师儿
博客等级 码龄9年 259粉丝 718原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值