mn演算法
1. 涓閬撴暟瀛﹁В鏂圭▼錛屾眰瑙mn絳変簬澶氬皯錛岃佸啓榪囩▼錛
鎮ㄥソ錛岃繖涓棰樼洰鍐欏湪榪欎釜綰稿矓浜涓婅佽厞婕忎簡錛岃佺敤鍒伴煢杈懼畾鐞嗘潵渚嶇儌瑙d竴鍏冧簩嬈℃柟紼嬶紝M,N 涓や釜鏁板垎鍒鐢ㄤ唬鍏ユ秷鍏冩硶錛岃繕鏈変笁瑙掑嚱鏁扮殑綆楁硶錛岃繖涓棰樼洰瀵逛簬鍒濅腑鐢熸潵璇達紝緇煎悎鎬ц繕鏄鏈変竴浜涚殑銆
2. 杈撳叆鏁存暟mn奼傛渶澶у叕綰︽暟鍜屾渶灝忓叕鍊嶆暟
涓嬮潰鐢ㄥ埌鐨勬柟娉曞彨杈楄漿鐩擱櫎娉曪紝鍏峰仛姝ラゅ備笅
鍏堢敤灝忕殑涓涓鏁伴櫎澶х殑涓涓鏁幫紝寰楃涓涓浣欐暟錛
鍐嶇敤絎涓涓浣欐暟闄ゅ皬鐨勪竴涓鏁幫紝寰楃浜屼釜浣欐暟錛
鍙堢敤絎浜屼釜浣欐暟闄ょ涓涓浣欐暟錛屽緱涓懼仛琛$涓変釜浣欐暟錛
榪欐牱閫愭$敤鍚庝竴涓鏁板幓闄ゅ墠涓涓浣欐暟錛岀洿鍒頒綑鏁版槸0涓烘銆傞偅涔堬紝鏈鍚庝竴涓闄ゆ暟灝辨槸鎵奼傜殑鏈澶у叕綰︽暟錛堝傛灉鏈鍚庣殑闄ゆ暟鏄1錛岄偅涔堝師鏉ョ殑涓や釜鏁版槸浜掕川鏁幫級銆
鐢–璇璦錛
#include <stdio.h>
main()
{
int p,r,n,m,temp;
printf("璇瘋緭鍏ヤ袱涓姝f暣鏁皀,m"); //榪欎釜鍦版柟榪愭e仛琛屾椂瑕佹敞鎰忥紝涓や釜鏁板瓧涔嬮棿瑕佺敤鈥滐紝鈥濆壊寮銆
scanf("%d,%d"鑳℃簮,&n,&m);
p=n*m;
if(n<m)
{temp=n;
n=m;
m=temp;
}
while(m!=0)
{
r=n%m;
n=m;
m=r;
}
printf("瀹冧滑鐨勬渶澶у叕綰︽暟涓猴細%d\n",n);
printf("浠栦滑鐨勬渶灝忓叕鍊嶆暟涓猴細%d\n",p/n);
}