文章列表
 
您正在查看 "数论" 分类下的文章

2010-03-25 14:38

//今天偶然看到了反素数这个概念,于是便学习了一会,找到hdu2523反素数这道题。

#include <iostream>  
#include <cmath>
using namespace std;  
int counter;  
int main()  
{  
    int t,a,b,m,flag;  
//freopen("in.txt","r",stdin);
    scanf("%d",&t);  
    while(t--) 

 
2010-01-08 13:34

//求n个数的最大公约数,没有指明一次输入有多少个,得用换行符判断,

第一次提交:

#include<iostream>
using namespace std;
int num[10001];
char c;
int gcd(int a, int b)
{
if(a<b)
swap(a, b);
if(b==0)
return a;
else
{
return gcd(b, a%b);
}
}
int ngcd(int *a, int n)
{
if(n==1)
return

 
2009-07-27 18:13

欧几里得算法中,计算 x, y 的最大公约数的方法是辗转相除,例如:

gcd(26, 15)

26 % 15 = 1 ... 11
15 % 11 = 1 ... 4
11 % 4 = 2 ... 3
4 % 3 = 1 ... 1
3 % 1 = 3 ... 0

可知,gcd(26, 15) = 1

如果 gcd(x, y) = r,那么有 ax + by = r,可以看出,上面的步骤实际上是可以直接得出 a, b 的:
null
26 % 15 = 1 ... 11 => 11 = 26 - 15 ;(1 1 -1)
15 % 11 = 1 ... 4 => 4 = 15 - 11 = 15 - (26 -

 
 
   
 
 
文章存档
 
     
 
最新文章评论
  

条理很清晰
 

什么是多重队列?跪求!!!
 

orz ...
 

请问这个代码,错在什么地方了?一直是 running time error 我是不是少考虑了什么条
 

#include<iostream> #include<algorithm> #include<string.h> using namespace std;
   
帮助中心 | 空间客服 | 投诉中心 | 空间协议
©2012 Baidu