Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ > Re: Can "cout" ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 5 Topic 45695 of 48612
Post > Topic >>

Re: Can "cout" do evil?

by saya-jin <gyula.gubacsi@[EMAIL PROTECTED] > May 2, 2008 at 03:21 AM

Sorry dude, but this program with or without the line <1> works. There
is another issue with this code but this issue isn't related with the
cout stream. On Visual C++ 2005 compiler...

saya-jin

On May 2, 4:48 am, thomas <FreshTho...@[EMAIL PROTECTED]
> wrote:
> #include<iostream>
> #include<vector>
> #include<map>
> #include<set>
> #include<iterator>
> #include<string>
> #include<algorithm>
>
> using namespace std;
>
> #define M 1000009
>
> vector<int> primes;
>
> //generate C(n, 1), C(n, 2), ...
> void dfs(vector<int> &mp, int its, int i, vector<int> &temp){
>     if(i==0) {
>         int s=1;
>         for(vector<int>::iterator it2(temp.begin()); it2!=temp.end();
> it2++){        s=s*(*it2);        }
>         if(s>1) mp.push_back(s);   return;
>     }
>     if(mp[its]==0) return;
>     int my_its(its);
>     for(vector<int>::iterator it_t(mp.begin() + its); *it_t!=0;  it_t+
> +, my_its++){
>         temp.push_back(*it_t);
>         dfs(mp, my_its+1, i-1, temp);
>         temp.pop_back();
>     }
>
> }
>
> int main(){
>     vector<int> numbers;    numbers.resize(M, 0);
>
> //generate prime numbers
>     primes.push_back(2);
>     for(int i=3; i<M; i+=2){
>         if(numbers[i]==1) continue;
>         primes.push_back(i);
>         for(int j=i+i; j<M; j+=i)
>             numbers[j] = 1;
>     }
>
>     int m, k;
>     while(cin>>m>>k){
>         vector<int> mprime;   int mm=m;
>         cout<<1;              //<1>
>
> //prime factors of m
>         for(vector<int>::iterator it(primes.begin()); it!=primes.end()
> &&*it<=mm; it++){
>             if(mm%(*it)==0) mprime.push_back(*it);
>             while(mm%(*it)==0) mm=mm/(*it);
>         }
>
> //generate C(n,i), push the multiplication result of the "i" factors
> in mprime, seperated by 0
>         int msize = mprime.size();
>         mprime.push_back(0);
>         for(int i=2; i<=msize; i++){
>             vector<int> temp;
>             dfs(mprime, 0, i, temp);
>             mprime.push_back(0);
>         }
>
> //calculate the k-th number x with gcd(x,m)=1
>         int result = 0;   int total=0;  bool change=true;
>         while(total<k){
>             result += (k-total);    total=result;
>             for(vector<int>::iterator it(mprime.begin()); it!
> =mprime.end()&&*it<=m&&*it<=result; it++){
>                 if(*it==0){ change=(change?false:true); continue;}
>                 if(change)    total-=(result/(*it));
>                 else total+=(result/(*it));
>             }
>         }
>         cout<<result<<endl;
>     }
>
> }
>
> ---------code--------
> The above is the code to calculate the k-th number x of m having
> gcd(x,m)=1
> notice the line marked <1>
> If the <1> line exists, everything works fine.
> But if I remove line <1>, the guy says error.
> what's wrong? Can a simple "cout" do anything evil?
 




 5 Posts in Topic:
Can "cout" do evil?
thomas <FreshThomas@[E  2008-05-01 19:48:19 
Re: Can "cout" do evil?
"Alf P. Steinbach&qu  2008-05-02 05:48:27 
Re: Can "cout" do evil?
saya-jin <gyula.gubacs  2008-05-02 03:21:24 
Re: Can "cout" do evil?
"Jim Langston"   2008-05-02 04:42:15 
Re: Can "cout" do evil?
thomas <FreshThomas@[E  2008-05-04 09:22:21 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed Dec 3 15:39:18 CST 2008.