-3
的連續分數顯示我奇怪的錯誤下面的代碼有理數
#include<iostream>
#include<math.h>
#include<vector>
using namespace std;
int gcd(int a,int b) { return (b==0 ?a:gcd(b,a%b));}
long long gcd(long a,long b) { return (b==0 ?a:gcd(b,a%b));}
template<class Int> Int gcd(Int a,Int b) { return (b==0 ?a:gcd(b,a%b));}
template<class Int>
struct Triple
{
Int d,x,y;
Triple(Int q,Int w,Int e) :d(q),x(w),y(e) {}
};
//extended GCD
/* computes d=gcd(a,b)
also x and y such that d=a*x+y*b and return tripls (d,x,y)
*/
template<class Int>
Triple <Int> egcd(Int a,Int b) {
if(!b) return Triple<Int>(a,Int(1),Int(0));
Triple<int>q=egcd(b,a%b);
return Triple<Int>(q.d,q.y,q.x-a/b*q.y);
}
/* modular :inear Equation solver */
/* given integer a,b,n solve ax=b(mod n)
create vector,which will be empthy in case of no solution
*/
template<class Int>
vector<Int>msolve(Int a,Int b,Int n){
if(n<0){ n=-n;}
Triple<Int> t=egcd(a,n);
vector<Int> r;
if(b%t.d) return r;
Int x=(b/t.d*t.x)%n;
if(x<Int(0)) x+=n;
for(Int i=0;i<t.d;i++)
r.push_back((x+i*n/t.d)%n);
return r;
}
template<class Int>
Triple<int>ldioph(Int a,Int b,Int c){
Triple<Int> t=egcd(a,b);
if(c%t.d) return Triple<Int>(0,0,0);
t.x*=c/t.d;t.y*=c/t.d;
return t;
}
/*
// given a and n ,solves ax=1(mod n)
return 0 if there is no solution
*/
template<class Int>
Int inverse(Int a,Int n){
Triple<Int> t=egcd(a,n);
if(t.d>Int(1)) return Int(0);
Int r=t.x%n;
return (r<Int(0)?r+n:r);
}
/*
Successive Squaring (for arbitrary power)
computes b^p mod m,whants p>=0,m>=1;
if(m is zero) (which is by default) no modding is done,expect full power
*/
template<class Int>
Int powmod(Int b,Int p,Int m=0){
vector<bool>bits;
while(p>0){
Int np=p/2;
bits.push_back(np+np!=p);
p=np;
}
Int r=1;
for(Int i=bits.size()-1;i>=0;i--){
r*=r; if(m>0) r%=m;
if(bits[i]) { r*=b;if(m>0) r%=m;}
}
return r;
}
template<class Int>
void factor(Int n,vector<Int>&v){
Int sq=Int(sqrt((double)n));
for(Int i=2;i<=sq;i++){
if(n%i) continue;
v.push_back(i);
n/=i--;
sq=Int(sqrt((double)n));
}
if(n>1) v.push_back(n);
}
/* Euler totient function
returns number of psoitive integers that are relatively prime to n
*/
int phi(int n){
vector<int> p;
factor(n,p);
for(int i=0;i<(int)p.size();i++){
if(i && p[i]==p[i-1]) continue;
n/=p[i];
n*=p[i]-1;
}
return n;
}
/* returns number of positive divisors of n
complexity : about O(sqrt(n))
requires : the constructor Int::Int(double)
*/
template<class Int>
Int divisors(Int n){
vector<int> f;
factor(n,f);
int k=f.size();
vector<Int>table (k+1,Int(0));
table[k]=Int(1);
for(int i=k-1;i>=0;i--){
table[i]=table[i+1];
for(int j=i+1; ;j++)
if(j==k || f[j]!=f[i]){
table[i]+=table[j]; break;
}
`
}
return table[0];
}
/* last problem continuous FrACTIONS OF RATIONALS
*/
/* complexity of O(logn)*/
template<class Int>
void contFract(Int m,Int n,vector<Int>&ans){
while(n){
ans.push_back(m/n);
m%=n;
m^=n^=m^=n;
}
}
int main(){
vector<int>v;
vector<int>::iterator it;
int m=1000;
int n=300;
contFract(m,n,v);
for(it=v.begin();it!=v.end();it++)
cout<<*it<<" ";
return 0;
}
1>c:\users\datuashvili\documents\visual studio 2010\projects\number_theory\number_theory\number_theory.cpp(160): error C2018: unknown character '0x60'
,我無法理解什麼是手段,可能有人幫助我嗎?
請修改您的代碼。如果你不通過顯示格式正確的代碼來幫助他們,你希望別人能夠幫助你嗎? –
是的,但這兩次downvoting什麼是地獄 –