CERC2017 F: Faulty Factorial 简单数论题

iOS激活锁绕过工具技术原理与安全风险深度剖析 设备激活验证是移动操作系统安全架构的核心环节,其原理涉及设备标识符校验、服务器端状态查询与本地安全芯片协同工作。在iOS生态中,激活锁作为关键的安全防线,通过硬件级的安全飞地(Secure Enclave)与云端服务器多重校验机制,构建了设备与Apple ID的强绑定关系。从技术价值看,这套机制有效提升了设备丢失后的非法使用门槛,保护了用户数字资产。然而,针对激活锁的绕过技术,如利用Checkm8这类Bootrom漏洞进行系统欺骗,或尝试伪造激活记录,揭示了系统在特定攻击向量下的潜在脆弱性。这类技术常被应用 阅读详情

传送门:Faulty Factorial



分析:

分为n==p, n>=2*p, 2*p>n>p , n<p 四种情况讨论

其中n==p使用到了威尔逊定理,且注意, n=p=2,无解

情况不难想,看代码吧


#include <iostream>
using namespace std;

typedef long long LL;
LL n,p,r;

LL qpow(LL a, LL b) {
    LL ans = 1;
    while (b) {
        if (b&1) ans = ans*a%p;
        a = a*a%p;
        b>>=1;
    }
    return ans;
}


int main(){
    cin >> n >> p >> r;

    if (n == p) {
        if (r == 0) {
            if (n == 2) cout << -1 << " " << -1 << endl;
            else cout << 2 << " " << 1 << endl;
            return 0;
        }
        else {
            for (LL i=1; i<p; i++)  if (i*(p-1)%p==r) {
                cout << p << " " << i << endl;
                return 0;
            }
            cout << -1 << " " << -1 << endl;
            return 0;
        }
    }

    if (n>=2*p) {
        if (r == 0) cout << p+1 << " " << 1 << endl; else cout << -1 << " " << -1 << endl;
        return 0;
    }

    if (n>p) {
        if (r == 0) cout << p+1 << " " << 1 << endl;
        else {
           LL t = 1;
           for (LL i=2; i<=n; i++) if (i!=p) t = t*i%p;
           for (LL i=1; i<p; i++) if (t*i%p==r) { cout << p << " " << i << endl; return 0; }
           cout << -1 << " " << -1 << endl;
        }
        return 0;
    }

    if (n<p) {
        if (r == 0) cout << -1 << " " << -1 << endl;
        else {
            LL t = 1;
            for (LL i=2; i<=n; i++) t = t*i%p;
            t =  qpow(t,p-2);
            for (LL i=2; i<=n; i++) {
                LL tmp = r*i%p*t%p;
                if (tmp>=1 && tmp<i) { cout << i << " " << tmp << endl; return 0; }
            }
            cout << -1 << " " << -1 << endl;
        }
    }

    return 0;
}

别再为电路自激发愁了:手把手教你用吸波材料搞定微波腔体谐振(附HFSS仿真设置) 本文详细解析了微波腔体谐振问题的工程解决方案,重点介绍了吸波材料的选型、安装工艺及HFSS仿真设置。通过实际案例和计算工具,帮助射频工程师有效抑制腔体自激,提升系统稳定性。特别适用于35GHz毫米波雷达等高频电路设计场景。 阅读详情

相关推荐

LC滤波器设计实战:从理论计算到PCB布局的完整指南

滤波器是信号处理与电路设计中的基础组件,用于从复杂信号中提取特定频率分量或抑制干扰噪声。其核心原理基于电感(L)和电容(C)等无源元件的频率选择特性,通过特定的网络拓扑实现幅频与相频特性的塑造。在工程实践中,LC滤波器因其结构简单、可靠性高、成本可控,成为射频、模拟及电源电路中的关键技术手段。其设计价值在于将理论网络综合转化为可量产、高性能的硬件解决方案,广泛应用于通信系统、音频处理、电源净化和传感器信号调理等场景。本文聚焦于LC滤波器的工程设计全流程,深入剖析了巴特沃斯、切比雪夫等经典类型的选型权衡,并重

weixin_34194829的博客 273

CERC2017 F-Faulty Factorial【数论】

题目描述 The factorial of a natural number is the product of all positive integers less than or equal to it. For example, the factorial of 4 is 1 · 2 · 3 · 4 = 24. A faulty factorial of length n is simil...

include_peng的博客 641

【学习总结】飞跨电容三电平boost拓扑发波分析与matlab仿真

正常工作时,飞跨电容的电压大约控制在输出电压的一半,降低了开关器件的耐受电压。

晞子的技术札记 1万+

【E:Faulty Factorial】(数论,循环节)

**链接**:http://sua2018.contest.codeforces.com/group/J1GbXiu37w/contest/227105 **题意**:在1*2*3*......*n中改变一个数为比它小的数,使得%p等于r.输出任意一个解 2&lt;=n&amp;&amp;n&lt;=1e18 2&lt;=p&amp;&amp;p&lt;1e7 **分析**:n很大,从p入...

running_acmer的博客 695

【FnOS飞牛云 | NAS存储】旧电脑不吃灰,手把手教你搭建完全属于自己的私人网盘

打造属于自己的NAS私人网盘,亲测有效,值得一试

木子Linux的博客世界 9413

Landsat9 地表温度反演方法

landsat9地表温度反演及缺失值处理方法

xiangliu12345的博客 3916

CERC2017 F: Faulty Factorial 简单数论题

1 #include <iostream> 2 using namespace std; 3 #define ll long long 4 const int N = 10000006; 5 ll n,p,r; 6 ll poww(ll a,ll b){ 7 ll ans =1ll; 8 while(b){...

weixin_30299709的博客 189

关于RTP时间戳以及播放器对时间戳的处理

首先,了解时间戳几个基本概念: 时间戳单位:时间戳计算的单位不是秒之类的单位,而是由采样频率所代替的单位,这样做的目的就是为了是时间戳单位更为精准。比如说一个音频的采样频率为8000Hz,那么我们可以把时间戳单位设为1 / 8000。 时间戳增量:相邻两帧之间的时间差(以时间戳单位为基准)。 采样频率: 有些地方也叫时钟频率,即 每秒钟抽取样本的次数,例如音频的采...

toshiba689的专栏 3052

【数论+思维】 GYM101620F Faulty Factorial

http://codeforces.com/gym/101620/attachments 给你n,p,r,(1&lt;=n&lt;=1e18,p是&lt;=1e7的质数,r&lt;p) n!中任选一个数换成比此数小的数,要求得到的新的乘积%p==r,问是否可以 不可以输出 -1 -1,可以输出 a b,(把a换成b) 分类讨论 1、r==0,如果r==0,     (1) 当n&lt;...

qq_41037114的博客 350

elmos 524系列芯片笔记

芯片的工作工作原理:集成芯片Elmos524.03有发射回路和接收回路,手册有关的内部原理图,大致如下: 芯片会产生固有频率的电压信号,信号通过引脚DRV1、2输出给外部压电陶瓷片,产生固定频率的机械波,也就是所谓的超声波,超声波遇到障碍物时会反射,反射信号经过AINS、D引脚进入芯片,在芯片内部先后经过GAIN放大,滤波然后进入比较器,滤波后的信号(signal)同预先设定的阈值(threshold)比较产生信号输出。此信号最终会连接MCU处理器,需要重点关注。 基于这个内部的工作原

qq_38230916的博客 2484

Ubuntu虚拟机磁盘扩容实战:5分钟搞定gparted分区调整(附常见错误修复)

本文详细介绍了在Ubuntu虚拟机中使用gparted工具进行磁盘扩容的实战步骤。针对常见的交换分区阻碍问题,提供了从禁用交换空间、删除旧分区、调整主分区大小到重建交换分区并更新系统配置的完整解决方案,帮助用户在5-10分钟内安全高效地解决磁盘空间不足的难题。

1a2s3d4f5g的博客 669

mcpc2017 Faulty Robot (bfs+dfs)

问题 : Faulty Robot时间限制: 1 Sec  内存限制: 128 MB题目描述As part of a CS course, Alice just finished programming her robot to explore a graph having n nodes, labeled 1, 2, . . . , n, and m directed edges. Initial...

ekqm1998的博客 482

基于STM32L4XX、HAL库的MCP4561数字电位器驱动程序设计

/ HAL库需要左移一位。* @param address: 设备地址(0x2C-0x2F)* @param hmcp: MCP4561句柄。* @param hmcp: MCP4561句柄。* @param hmcp: MCP4561句柄。* @param hmcp: MCP4561句柄。* @param hmcp: MCP4561句柄。* @param hmcp: MCP4561句柄。* @param hmcp: MCP4561句柄。* @param hi2c: I2C句柄。

zhusl6688的博客 340

和Leo一起做爱数学的好孩子之 CERC2017 Faulty Factory 阶乘谜题

给定n,质数p和一个目标余数r 你需要改变n的阶乘中的一个数字,使得其积模p余r。 感觉不能融会贯通 我以为是个EXGCD的神仙题 首先n看似很大,但是明显n并不是完全有用 时若余数不为0则无解 对于有: 这个明显是一个不定方程,算出最小解再判断和p的大小关系就好了 但是怎么办? 由于这个不超过1e7我认为直接枚举变的暴力EXGCD 但很明显这是不能A掉的(虽然开了3s) ...

LeoJAM的博客 2468

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

深度学习工具包 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)四、最小公倍数(lcm)五、同余六、快速幂七、扩展欧几里得八、逆元九、模运算例题一、J - Sum二、C - A/B 常识 一、整除 定义 若整数a除以非零整数b,商为整数,且余数为零, 我们就说a能被b整除(或说b能整除a)b|a,否则b∤a。 基本性质 1.若b|a,c|a,且b和c互质,则bc|a 2.若a|b,且b|c,则a|c 3.若b|a,且b|c,则b|(a±c) 4.若c|a,且c|b,则对于任意整数m、n,有c|(ma+nb) .

weixin_50522312的博客 1575

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

数论的学习及刷题

数论是研究整数的性质、结构和关系整数基本性质的一类方法。

m0_74196680的博客 1497

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

超简单的数论入门题

选定方向了,这篇博客将伴随我学习数论和某些数学知识 1.欧几里得算法(辗转相除法) 用途:求两个数最大公约数 公式:a%b=b%(a%b) 代码 : ll gcd(ll a,ll b) {return !b?a:gcd(b,a%b);} ///函数形式 2.拓展欧几里得 用途:求不定方程最小解( 方程应满足ax+by=gcd(a,b),否则无解) 公式推导:(嫖的) 假...

permi_yaxileni的博客 700

CERC 2017 H:Hidden Hierarchy (模拟)

Hidden Hierarchy时间限制:1 Sec内存限制:512 MB提交:84解决:11[提交][状态][讨论版][命题人:admin]题目描述You are working on the user interface for a simple text-based file explorer. One of your tasks is t...

weixin_30566063的博客 202

CERC2017 H Hidden Hierarchy(树+模拟)

题意: 在一些给定的目录里按要求展开到制定大小并按字典序输出 思路: 因为有目录这个东西,所以想到模拟一个类似字典树的东西,不过这里每个儿子可能有n个节点,而且不能O(1)查询了 代码超长。。 #include<iostream> #include<cstdio> #include<algorithm> #include<cmath&g...

weixin_30820077的博客 154

Factorial

Problem Description The most important part of a GSM network is so called Base Transceiver Station (BTS). These transceivers form the areas called cells (this term gave the name to the cellular pho

No_Retreats的专栏 831

Gym - 101620F 数论

https://vjudge.net/problem/Gym-101620F网上的ACM群里认识的朋友问我的一道数论题还是比较水的由于p的数量级只有1e7导致n的数据范围只能控制在1e7然后就是各种逆元推式子但是要注意很多细节:AC代码:#include&lt;bits/stdc++.h&gt; using namespace std; typedef long long ll; ll quick...

Gipsy 474

CodeForces Gym 101620简要题解

Assignment Algorithm模拟。#include <bits/stdc++.h> #define xx first #define yy second #define mp make_pair #define pb push_back #define mset(x, y) memset(x, y, sizeof x) #define mcpy(x, y) memcpy(x, y, si

wxh010910 1829

UPC-5083 - Hidden Hierarchy - 模拟

题解链接: https://lucien.ink/archives/154/ 题目链接: http://exam.upc.edu.cn/problem.php?id=5083 题目: 题目描述 You are working on the user interface for a simple text-based file explorer. One of your ta...

LucienShui 481

简单数论的题解

给定n,pn,p,求值: [(∑i=1n∑j=1ni2j2)×36]mod p[ (\sum_{i=1}^n \sum_{j=1}^n i^2 j^2 ) \times 36 ]mod \ p[(i=1∑n​j=1∑n​i2j2)×36]mod p 让大家接触提前接触一下数论 [(∑i=1n∑j=1ni2j2)×36]mod p [ (\sum_{i=1}^n \...

ZHK's blog 374

RMRC2017 Polyline Simplification

给出点集,构成曲折线,如下图,每两个线构成一个三角形,三点共线认为面积为零,每次删掉面积最小的三角形和其顶点,余下两点自动连接,如下图,删掉面积S2(假设S2面积最小),p3也被删去,形成下面的情况,一直删到剩余边数为m时停止,把每次删的点输出来;按题意模拟即可;利用向量叉乘求出面积存到set或priority_queue中,记录每个点前驱后驱,删除时不断更新;坑点:将一个三角形删除后,会产生一个...

OJBFOWE的博客 413

lucas 定理,组合数取模

Lucas 定理求 Cmn%pC^{m}_n \% p 的值,如果n,m的值过大,不易直接求出,所以利用lucas定理定理 Cmn%pC^{m}_n \% p =Cm/pn/p∗= C^{m / p}_{n/p}*Cm%pn%p C^{m \% p}_{n \% p} 证明:百度百科预备知识①  Cip%p=0C^i_p \% p = 0p 为素数且,i≠p and i≠0i \not= p

海边拾贝,沧海一粟 243
上一篇: 2-SAT专题练习 (题解+AC代码)
下一篇: 2018, XI Samara Regional Intercollegiate Programming Contest M题-Forgotten Spell
罗侯
博客等级 码龄10年 135粉丝 258原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值