2013长春网络赛 D 大数+gcd

最大公约数GCD 题目描述 两个正整数的最大公约数(GCD)是能够整除这两个整数的的最大整数。 计算GCD有三种方法: (1)穷举法:由于a,b的最大公约数不可能比a和b中的较小者还大,否则一定不能整除它。因此先找到a和b中的较小者t,然后从t开始逐次减1尝试每种可能,即检验t到1之间所有正整数,第一个满足公约数条件的t,就是a和b的最大公约数。 (2)欧几里得算法,也称辗转相除法。对正整数a和b,连续进行... 阅读详情

最近真的有点高产似那啥了_(:з」∠)_

昨天晚上组队赛的时候没想到要用JAVA大数做

直到比赛结束后 别的队伍说用JAVA做就能过 (有点森气自己没尝试JAVA)

这是一道可以面向答案推出公式的题目

(队友很大胆的猜测了 但是我们卡在了大数上 直接WA了)

上题目

D

MMM got a big big big cake, and invited all her M friends to eat the cake together. Surprisingly one of her friends HZ took some (N) strawberries which MMM likes very much to decorate the cake (of course they also eat strawberries, not just for decoration). HZ is in charge of the decoration, and he thinks that it's not a big deal that he put the strawberries on the cake randomly one by one. After that, MMM would cut the cake into M pieces of sector with equal size and shape (the last one came to the party will have no cake to eat), and choose one piece first. MMM wants to know the probability that she can get all N strawberries, can you help her? As the cake is so big, all strawberries on it could be treat as points. 

Input

First line is the integer T, which means there are T cases. 
For each case, two integers M, N indicate the number of her friends and the number of strawberry. 
(2 < M, N <= 20, T <= 400) 

Output

As the probability could be very small, you should output the probability in the form of a fraction in lowest terms. For each case, output the probability in a single line. Please see the sample for more details. 

Sample Input

2
3 3
3 4

Sample Output

1/3
4/27

很容易就推出公式 

 n / (m^(n-1))

kuangbin博客说是积分求得的 (讲真 我没有很懂 但是可以凭感觉推公式emmm)

附上巨佬的传送门:http://www.cnblogs.com/kuangbin/p/3346109.html 

刚刚用JAVA写了一发 AC了

上代码

PS:其中代码  @SuppressWarnings(value = { "all" }) 是用来注释掉警告的(某学长教我的)

import java.math.*;
import java.io.*;
import java.math.BigInteger;
import java.util.*;

//@SuppressWarnings(value = { "all" })

public class Main {
	public static BigInteger GCD(BigInteger a, BigInteger b) {
		if (b.compareTo(BigInteger.ZERO) == 0)
			return a;
		else
			return GCD(b, a.mod(b));
	}

	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		int t = cin.nextInt();
		// BigInteger zero = BigInteger.valueOf(0);
		BigInteger one = BigInteger.valueOf(1);
		while (t-- > 0) {
			int n = cin.nextInt();
			int m = cin.nextInt();
			BigInteger N = BigInteger.valueOf(n);
			BigInteger M = BigInteger.valueOf(m);
			BigInteger b = BigInteger.ONE;
			for (int i = 1; i < m; i++) {
				b = b.multiply(N);
			}
			BigInteger k = GCD(b, M);
			b = b.divide(k);
			M = M.divide(k);
			System.out.println(M+"/"+b);
		}
	}
}

加油鸭~~

C++ ! 最大公约数 !(大数) 题目描述 从n个不同元素中,任取m(m≤n)个元素并成一组,叫做从n个不同元素中取出m个元素的一个组合;从n个不同元素中取出m(m≤n)个元素的所有组合的个数,叫做从n个不同元素中取出m个元素的组合数,用符号c(n,m)表示。 计算公式为:c(n,m)=n!/((n-m)!×m!) 现在你的任务是求出C(2n,1),C(2n,3),C(2n,5),…,C(2n,2n-1)的最大公约数。 解答要求 ... 阅读详情

相关推荐

Android SDK安装教程(超详细),从零基础入门到精通,从这篇开始_android sdk下载安装

Android SDK安装教程(超详细),从零基础入门到精通,从这篇开始_android sdk下载安装

Jinmindong 5013

hdu java大整数gcd_GCD、LCM --算法竞赛专题解析(20)

本系列文章将于2021年整理出版。前驱教材:《算法竞赛入门到进阶》 清华大学出版社网购:京东 当当   做者签名书:点我公众号同步:算法专辑暑假福利:胡说三国有建议请加QQ 群:567554289html最大公约数java1. GCD定义整数a和b的最大公因数是指能同时整除a和b的最大整数,记为gcd(a, b)。例如:gcd(15, 81) = 3,gcd(0, 44) = 44,gcd(0, ...

weixin_35660038的博客 656

优快云余额充值前必读:这5个隐藏条款,90%的开发者都忽略了(附iOS内购避坑指南)

本文揭示了优快云余额充值中90%开发者忽略的5个隐藏条款,包括不可退款规则、iOS内购限制、账号安全责任等关键内容,特别提供了iOS内购避坑指南,帮助开发者避免资金损失和账号风险。

weixin_26765287的博客 147

大数求gcd模板(高精度)

给两个大数求最大公约数。 #include<bits/stdc++.h> using namespace std; const int N=1e6+5,inf=1<<29,base=10000;//10000而不是100000,不然容易爆掉! int T; int a[1000],b[1000],c[1000],f[1000]; int read() { int f...

czyzx的博客 1016

别再死记硬背窗函数公式了!用MATLAB实战汉宁窗FIR滤波器,从频谱图看懂‘主瓣’和‘旁瓣’

本文通过MATLAB实战演示汉宁窗FIR滤波器的设计过程,帮助读者从频谱图直观理解主瓣与旁瓣的特性。文章详细对比了矩形窗与汉宁窗的频谱差异,并提供了高通滤波器设计的完整代码示例,适用于数字信号处理学习和工程应用。

weixin_30555125的博客 490

从仿真到现实:BeamDojo双足机器人项目实战指南(附完整配置清单)

本文提供了一份基于BeamDojo项目的双足机器人从仿真训练到现实部署的完整实战指南。详细拆解了硬件选型(如宇树G1、Jetson Orin NX、Livox Mid-360)、Isaac Gym仿真环境搭建、强化学习训练技巧(如双评论家架构、课程学习)以及关键的Sim2Real迁移策略,旨在帮助开发者将前沿研究成果转化为可落地的工程实践。

hhh00的博客 875

四种求最大公约数算法

四种求最大公约数算法 1. 题目 运行最大公约数的常用算法,并进行程序的调式与测试,要求程序设计风格良好,并添加异常处理模块(如输入非法等)。 分析最大公约数的4种算法,补充完整算法, 进行程序的调式与测试,比较4种GCD算法在给定不同规模测试数据的情况下的平均运行时间,比较4种算法在不同条件下的优劣。 2.算法内容 1.辗转相除法 辗转相除法(又名欧几里德法)C语言中用于计算两个正整数a,b的最...

hi_你好 1万+

Mike 21如何制作随水深变化的糙率文件

MIKE 21如何制作随水深变化的糙率文件

zhuzhujiayoua的博客 2249

C++求最大公因数(gcd)的六重境界

求最大公因数的六种解法

ceshyong的博客 1万+

【FPGA】定点数运算中的位宽优化与截取策略

本文深入探讨了FPGA定点数运算中的核心挑战——数据位宽优化与截取策略。针对定点数在加法、乘法等运算中位宽膨胀的问题,文章详细分析了位宽变化规律,并对比了直接截断、四舍五入和收敛舍入三大截取策略的优缺点及硬件实现方法。通过实战指南与避坑经验,旨在帮助开发者在保证计算精度的同时,高效利用FPGA资源,实现性能与面积的平衡。

weixin_29181861的博客 116

海外购物商城源码 带即时通讯IM源码

在海外购物商城中,即时通讯IM源码可以为用户提供更便捷、高效的沟通方式,帮助解决跨国交易中的语言和文化差异问题。总之,即时通讯IM源码在海外购物商城中扮演着重要的角色,可以为用户提供更方便、高效的沟通方式,解决跨国交易中的语言和文化差异问题。(购买本专栏可免费下载栏目内所有资源不受限制,持续发布中,需要注意的是,本专栏为批量下载专用,并无法保证某款源码或者插件绝对可用,介意不要购买)实时翻译:即时通讯IM源码提供实时翻译功能,能够快速准确地翻译不同语言之间的文字、语音、视频等信息,帮助用户克服语言障碍。

很酷的站长的博客 259

记 2016 CCPC 长春站

得知今年我们打第一站时其实还是略微有些紧张的,不过二队打第一站想想还是有道理的。今年共有三站比赛要打,CCPC长春站,ICPC大连站和ICPC越南芽庄站,还是期待去芽庄比赛,可能会更爽。24号到了长春,当天因为要打北京赛区的网络赛,所以没有去现场打东北四省的热身赛,只派了后面的一个队伍去现场测了下环境,我们和女队在宾馆里打了网络赛。btw,午餐和晚餐都特别好,感谢我们的带队老师谢老师。第二天东北四省

你是我天边最美的云彩~~ 1849

【从零开始学习SLAM】官方tf教程小海龟跟随程序

ros tf 进行坐标系之间转换的运算和发布

小秋 AI SLAM 入门实战教程 2033

大数gcd模板

原文章:http://blog.youkuaiyun.com/ied98/article/details/42537989 #include #include #include #include #include using namespace std; #define maxn 1300 #define mod 100000000 struct bignu

black_miracle的博客 1595

精雕软件(JDpaint) 5.5 绿色版

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

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

原题: https://www.luogu.org/problemnew/show/P2152 java大数有个gcd的函数,但是我想自己套一下stein,于是。。。 import java.math.*; import java.util.*; public class Main { public static BigInteger _0=BigInteger.valueOf(0); ...

QAQ 1188

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

[大数GCD Stein算法] BZOJ 1876 [SDOI2009]SuperGCD

懒得写高精 python水过 a=(int)(input()) b=(int)(input()) while b!=0: t=a a=b b=t%b print a Stein 算法  只有减法和位移 a=(int)(input()) b=(int)(input()) c=0 while (a!=0 and b!=0): x=a&

雯舞 1061

SAP B1中文培訓教材_SDK

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

poj3101——Astronomy(大数数学&gcd)

Astronomy Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 5932   Accepted: 1337 Description There are n planets in the planetary system of star X. They orbit

我在浪里 895

HDU - 5050 (大数二进制gcd)

It’s time to fight the local despots and redistribute the land. There is a rectangular piece of land granted from the government, whose length and width are both in binary form. As th...

weixin_30646315的博客 211

poj 2429 GCD & LCM Inverse(大数质因数分解+DFS)

GCD & LCM Inverse Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 16973   Accepted: 3137 Description Given two positive integers a and b, we can easily cal

加载中... 659

HDU 5666 Segment(大数+gcd)

大意:给定一个直线方程x+y=p;(p为质数)求在第一象限围城的区域里格子的点数有多少。思路:一条直线上的格子点数为gcd(x,y),那么我们可以直接用三角形上加内的总点数减去在直线上的点数那么在直线上的点数为gcd(x,y)=gcd(x,y-x)(y>x)=gcd(x,p-y)=gcd(x,p)=1所以直线上的点数为0。 注意可能超__int64.import java.util.*; impo

Grit_ICPC的博客 584

实数gcd,大数快速乘与组合数取模

实数gcd 在计算几何的题目中,有时会需要你算两个角度的最大公因数(会有误差),具体操作和整数的gcd类似,但要注意输入可能会有0。 模板如下: double fgcd(double a,double b) { if(fabs(a) if(fabs(b) return fgcd(b,fmod(a,b)); }//fmod为math库的小数取余函数 大数快速乘 适用于那些中间

萌萌哒黑大帅的博客 1264

C++实现大整数运算包(加、减、乘、除、幂模、GCD、乘法逆)

1.问题描述大整数运算是现代密码学算法实现的基础,重要性不言而喻。大整数我们指的是二进制位512、1024和2048的数,一般的语言不支持。2.基本要求以类库头文件的形式实现。3.实现提示在选择了大整数的存储结构之后,主要实现以下运算:①模加;②模减;③模乘;④模整除;⑤模取余。这五种运算模拟手算实现。⑥幂模:利用“平方-乘法”算法实现。⑦GCD:利用欧几里得算法实现。⑧乘法...

我的书包哪里去了 7540

最大公约数(数论GCD)

4488: [Jsoi2015]最大公约数Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 264  Solved: 152[Submit][Status][Discuss]Description给定一个长度为 N 的正整数序列Ai对于其任意一个连续的子序列{Al,Al+1...Ar},我们定义其权值W(L,R )为其长度与序列中所有元素的最大公约数的...

sher杨的博客 1865

[电子设计大赛]射频宽带放大器设计报告

射频宽带放大器 摘要:该设计实现的射频宽带放大器,由固定增益放大部分、可变增益放大部分、单片机控 制部分组成。固定增益放大部分由宽带电流反馈型运算放大器OPA695构成,采用同相放大电 路,可变增益放大部分由宽带低功耗可变增益放大器LMH6502构成。单片机控制部分由 STM32F103VBT6核心电路、键盘、12864液晶、DAC组成,通过键盘输入所需增益值并显示在 LCD12864上,由单片机...

qq_41106543的博客 9807

POJ 2429 GCD & LCM Inverse(大数分解)

用大数分解的模板把lcm/gcd分解了,然后就会得到十几个质因子,然后我们dfs一次找到和最小的a和b就成了。 #pragma warning(disable:4996) #include #include #include #include #include #include using namespace std; //**********************************

acraz的专栏 530

hdu java大整数gcd_算法竞赛专题解析(20):数论--GCD和LCM

本系列文章将于2021年整理出版。前驱教材:《算法竞赛入门到进阶》 清华大学出版社网购:京东 当当   作者签名书:点我公众号同步:算法专辑暑假福利:胡说三国有建议请加QQ 群:567554289目录最大公约数1. GCD定义整数a和b的最大公因数是指能同时整除a和b的最大整数,记为gcd(a, b)。例如:gcd(15, 81) = 3,gcd(0, 44) = 44,gcd(0, 0) = 0...

weixin_32516005的博客 511
上一篇: PTA| L1-046 整除光棍 (JAVA代码)
下一篇: 算法分析 | 关于时间复杂度的知识点(1,n,log n,n*log n,n*2,n*3 的比较)
OneLine_
博客等级 码龄9年 48粉丝 72原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值