poj2417(Discrete Logging)-Baby Step Giant Step

CANoe LIN一致性测试之干扰测试Test moudle_LIN Disturbance Block 注意:相邻两个显隐性不同的bit不允许干扰,例如我同时选择bit6和bit7,相邻两个同显隐性的bit允许干扰,例如当我选择bit3和bit4,项,这里我选择ID:为0x2F(PID:0x6F)的frame。需按照具体测试规范实施干扰项,帧头和数据段都可以实现干扰。最近发现一个干扰测试模块,下面是一些具体使用方法。选择干扰项:PID的奇偶校验位(一致性测试干扰测试之手动测试。一个待测试frameD。 阅读详情

题目链接:Discrete Logging


题意: ,给你P(P为素数),B,N,让你求满足条件的最小的L,无解输出 no solution.


思路: ,求满足条件的最小x,若p为素数,可用Baby Step Giant Step算法


令m = sqrt(n), 则,先预处理出,存入haxi(hash)表里,

,,枚举i,看a^j是否在hash表中,如果找到了,就输出x = i * m + j。




代码:

# include <iostream>
# include <algorithm>
# include <cstdio>
# include <cstring>
# include <cmath>
# include <map>
using namespace std;
typedef long long ll;
const int maxn = (1 << 16);
int b, n, p;

struct Node {
    int val;
    int j;
    bool operator < (const Node& n) const {
        return val < n.val || (val == n.val && j < n.j);
    }
} haxi[maxn];

int exgcd(int a, int b, int& x, int& y) {
    if (!b) {
        x = 1; y = 0; return a;
    }
    int g = exgcd(b, a % b, y, x);
    y -= a / b * x;
    return g;
}

int f_inv(int a) {
    int x, y;
    int g = exgcd(a, p, x, y);
    return g == 1 ? (x + p) % p : -1;
}

int Search(int x, int len) {
    int l = 0, r = len - 1;
    while (l < r) {
        int m = (l + r) / 2;
        if (haxi[m].val >= x) r = m;
        else l = m + 1;
    }
    return haxi[l].val == x ? haxi[l].j : -1;
}

int main(void)
{
    while (~scanf("%d %d %d", &p, &b, &n)) {
        int len = 0;
        int m = sqrt(p + 0.5);
        int t = 1;
        for (int i = 0; i <= m; ++i) {
            haxi[len].val = t;
            haxi[len++].j = i;
            if (i != m) t = (ll)t * b % p;
        }
        sort(haxi, haxi + len);
        int ans = -1;
        int a0 = f_inv(t);
        int a = 1;
        for (int i = 0; i < m; ++i) {
            int val = (ll)n * a % p;
            int id = Search(val, len);
            if (id != -1) {
                ans = i * m + id; break;
            }
            a = (ll)a * a0 % p;
        }
        if (ans != -1) printf("%d\n", ans);
        else printf("no solution\n");
    }

    return 0;
}


真随机数与伪随机数 前面我们学习了LFSR,这个玩意落地到具体的应用是什么呢?没错是寄存器,这里在网络找到了几个回答,这里做个记录,下面一起来学习一下吧。 阅读详情

相关推荐

YOLOv8的Anchor-Free革新:从中心点预测到动态IoU匹配的全面解析

本文深入解析了YOLOv8采用Anchor-Free(无锚框)设计的核心优势与实现机制。通过摒弃预设锚框,模型直接预测目标中心点与宽高,结合解耦头、动态IoU匹配及Varifocal Loss等创新,显著简化了训练流程并提升了检测精度,尤其在小目标检测和模型泛化能力上表现突出。

weixin_29094301的博客 356

POJ 2417 Discrete Logging (baby_step,giant_step算法)

转载请注明出处,谢谢 http://blog.youkuaiyun.com/ACM_cxlove?viewmode=contents           by---cxlove 题目:http://poj.org/problem?id=2417 高次同余方程。   BL == N (mod P) 求解最小的L。由于数据范围很大,暴力不行 这里用到baby_step,giant_step算法。意

窝不是爱酱,喵~~~~ 6719

STM32CubeIDE之SHT3X温湿度传感器移植HAL库

有了前面的OLED的学习,这个学习起来也很快。 分以下几步走 1.你要有个温度传感器,SHT3X这个型号的,因为我要讲这个 2.你要有个STM32开发板(我用的是STM32L431RCT) 3.顺便找台电脑下载一个STM32CubeIDE 4.简单的找一个SHT3X的驱动,我是去某宝嫖的,一般卖这个的都有,这个驱动分两个文件,是.c和.h的,我直接把这两个放在下边 读了我上一篇的人,看这个应该很熟悉吧,一样的套路,学习方法是一样的,你就照搬就行 下面是sht3x.c的原文档,里面有个CRC..

qq_47736089的博客 2315

POJ 2417:Discrete Logging——Baby Step, Giant Step

题意:求最小的Y,满足XY mod Z = K高次同余方程,用hash做,套模板。。从网上找的模板与POJ 3243的区别在于:POJ 2417 保证P是素数且B POJ 3243 就没有这些好条件。这会导致麻烦,待会再说。一:#include #include #include #define maxn 65535 using namespace std; struct hash

Booky的专栏 537

VGG16

VGG16学习笔记

一去不复返的通信er 1177

开源的预测气象大模型与数据获取/可视化

「开源气象大模型与数据获取指南」摘要: 当前主流AI气象模型(如ECMWF的AIFS、DeepMind的GraphCast、华为Pangu等)主要基于ERA5/HRES数据训练。开源资源可通过ECMWF OpenData、GitHub仓库及Google Cloud获取,其中AIFS数据采用CCBY-4.0许可可商用,其他模型多有限制性许可。典型应用流程包括:1)通过Python包获取实时预报数据;2)加载预训练权重进行推理;3)使用xarray/cartopy或Zarr进行可视化。训练数据可从CDS下载ER

专注AI大模型,软件混淆,授权 795

POJ 2417 Discrete Logging (Baby Step Giant Step算法)

题目:LINK

Napoleon 972

点云数据生成DEM,并导出三维模型

点云数据生成DEM,并导出三维模型

qq_42540466的博客 2万+

poj2417 Discrete Logging(BSGS:Baby Step Giant Step)

题意:求L使B的L次幂与N对P同余。 题目很短,一开始以为是数学题,想着还要推公式,好麻烦。后来才发现有hint,但是并没有什么用,因为按公式敲完一定会超时。学长说用BSGS做,就找了一下模板,半知半解吧,没有完全搞懂,就当收集了一个新模板吧,感觉BSGS算法大多是都是解数学题,以后再做类似题的时候再做扩展。 #include #include #include #include #i

Willona_C的博客 803

TIBCO Jaspersoft Studio报表开发 使用教程-进阶版

本文学习内容容器定制二级目录三级目录 容器定制 二级目录 三级目录

吉哲的博客 7521

innovus:如何在init design之后新增参考库(lib/lef)

如题,在PR过程中经常会遇到这种问题,时序无法收敛,需要新增一套lvt或者hpc的库,怎么办?

m0_61544122的博客 5010

POJ 2417 Discrete Logging(Baby-Step,Giant-Step)

给出 p,b,n,p 为质数,求中 x 的最小解,如果没有输出 no solution int n,m,t; int i,j,k; //int a[N]; ll mul_mod(ll a,ll x,ll mod) { a%=mod; ll ans=0; while(x){ if(x&1) ans=(ans+a)%mod; x>>=1; a=(a+a)%mod; } ...

C_Dreamy的博客 358

AUTOSAR从入门到精通-中间件通信DDS(一)

汽车开放系统架构(automotive open system architecture,autosar)是由全球各大汽车oem、零部件供应商、汽车电子软件公司联合建立的一套标准协议。该协议规范了一个符合汽车电子软件开发的、开放的以及标准化的软件架构。最初的autosar规范的制定只考虑传统汽车电子电器架构,基于硬件算力有限场景,提供确定的功能。

getusushu的博客 1869

Baby-step-Giant-step(北上广深)之 Discrete Logging POJ - 2417

Baby-step-Giant-step: Baby-step-Giant-step算法,又叫北上广深算法,拔山盖世算法,大步小步算法。。。。 面向问题: 已知A, B, C,求X使得 A^x = B (mod C)(C为素数) 设m = sqrt(C)上取整, x = i*m + j, 那么 A^x = (A^m)^i * A^j, (0<=i , j< ...

浦柳人的博客 298

深度学习工具包 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")

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

poj 2417 Discrete Logging 数论baby_step,giant_step算法

题意: 给p,b,n求最小的l使b^l==n(mod p)。 题意: 相当于在0~p-1内搜索l满足同余式,baby_step,giant_step相当于分块的二分搜索,设m=sqrt(p), 则将p分为m*m,在m块内每块进行m个数的二分搜索。 代码://poj 2417 //sep9 #include #include #include using namespace std;

sepNINE的专栏 977

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

POJ 2417 Discrete Logging ( Baby step giant step )

Discrete Logging Time Limit:5000MS Memory Limit:65536K Total Submissions:3696 Accepted:1727 Description Given a prime P, 2 <= P < 231, an integer B, 2 <= B...

weixin_34384557的博客 131

POJ 2417 Discrete Logging (Baby-Step Giant-Step)

Discrete Logging Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 2819   Accepted: 1386 Description Given a prime P, 2 &lt;= P &lt; 231, an integer B, 2...

weixin_33698823的博客 225

POJ 2417 Discrete Logging(高次同余方程-Baby-Step,Giant-Step)

Description 给出P,B,N(P是素数),解方程B^L = N (mod P) Input 多组输入,每组用例占一行包括三个整数P,B,N,以文件为结束输入 Output 对于每组用例,如果方程有解则输出最小解,否则输出no solution Sample Input 5 2 1 5 2 2 5 2 3 5 2 4 5 3 1 5 3 2 5 3 3 5 3

ZSQ 678

POJ - 2417 Discrete Logging(Baby-Step Giant-Step)

d. 式子B^L=N(mod P),给出B、N、P,求最小的L。 s.下面解法是设的im-j,而不是im+j。 设im+j的话,貌似要求逆元什么鬼 c. /* POJ 2417,3243 baby step giant step a^x=b(mod n) n是素数或不是素数都可以 求解上式 0<=x<n的解 */ #include<iostream&g...

weixin_30672019的博客 113

Poj 2417 Discrete Logging (Baby Step Giant Step 解 a^x = b (mod n) n为素数)

Baby Step Giant Step 解 a^x = b (mod n) n为素数 以下内容节选自:AekdyCoin的空间 【普通Baby Step Giant Step】 【问题模型】 求解 A^x = B (mod C) 中 0 【思路】 我们可以做一个等价 x = i * m + j  ( 0 而这么分解的目的无非是为了转化为: (A^i)^m *

whyorwhnt的专栏 1731

poj 2417 Discrete Logging 求解模方程a^x=b(mod n),n为素数+模板题(baby_step giant_step)

#include #include #include #include #include #include using namespace std; #define LL long long //快速幂求a^b LL pow_mod(LL a,LL b,LL n) { LL s=1; while(b) { if(b&1)

冷月之殇 3423

POJ 2417 Discrete Logging (Baby-Step-Gaint-Step)

题意:求最小的x使得满足 a ^ x  % p = b % p, p是素数思路:学习学习 Baby-Step-Gaint-Step 算法, 用map存还超时了, 还是用的散列表。#include&lt;cstdio&gt; #include&lt;cstring&gt; #include&lt;cmath&gt; #include&lt;map&gt; #include&lt;iostream&g...

hnust_Derker的博客 312

【POJ 2417】 Discrete Logging

【题目链接】 http://poj.org/problem?id=2417 【算法】 Baby-Step,Giant-Step算法 【代码】 #include <algorithm> #include <bitset> #include <cctype&gt...

120

poj 2417 Discrete Logging(baby-step算法)

参考资料:http://www.cppblog.com/csu-yx-2013/archive/2012/07/29/185562.html?opt=admin #include #include #include #include using namespace std; #define MAX (1000000) long long nData[MAX]; long long nK

A place to record sth. 440

poj 2417 && poj3243(Baby-Step Giant-Step)

Discrete Logging Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 4624   Accepted: 2113 Description Given a prime P, 2 31, an integer B, 2 BL == N (mo

阳光下的泡沫 640

POJ2417 Discrete Logging 解高次同余方程

题目链接:http://poj.org/problem?id=2417 实现代码如下: (一) #include #include #include #include using namespace std; //baby_step giant_step // a^x = b (mod n) n为素数,a,b < n // 求解上式 0<=x < n的解 #defin

AC_Gibson的专栏 664

POJ 2417 Discrete Logging(BSGS算法,gcd(a,p)=1)

题目链接: POJ 2417 Discrete Logging 题意: 求ax≡b(modp)a^x ≡ b(mod p)的最小xx。(pp为素数,2≤a<p,1≤b<p2\leq a<p, 1\leq b<p) 分析: BSGS算法。BSGS算法。 一开始用mapmap一直TT,参(zhao)考(ban)了这里 用了hashhash才过。。。BSGSBSGS算法用于求解:ax=b(m

ramay7 898
上一篇: UVALive5009(Error Curves)-三分求极值
下一篇: UVALive7749(Convex Contour)-计算几何分类讨论
yaa123_
博客等级 码龄11年 5粉丝 28原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值