|
|
back to boardwhere is my mistake? Posted by ooo 11 Dec 2008 22:39 #include <iostream.h> bool z(int); void main() {int n,i,q=1; cin>>n; for(i=1;i<=n;i++) q*=2; for(i=0;i<10000;i++) if((z(i)) && (i%q==0)) {cout<<i; break;} if(i==10000) cout<<"No solution";} bool z(int x) {int j=0; while(x!=0) {if((x%10!=1) && (x%10!=2)) j++; x=x/10;} if(j==0) return true; else return false;} Re: where is my mistake? Imagine that n is 100. q (2 ^ 100) will be overflowed. You must have 10000 digits but not number under 10000=) |
|
|