Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int nrmagic(int n,int p,int q)
- {
- int m,ok=1,v[10]={};
- m=n;
- while(n!=0)
- {
- v[n%p]++;
- n/=p;
- }
- while(m!=0)
- {
- v[m%q]--;
- m/=q;
- }
- for(int i=0;i<=9;i++)
- {
- if(v[i]!=0)
- {
- return 0;
- }
- }
- return 1;
- }
- int main()
- {
- int n,k=0,p,q;
- cin>>n>>p>>q;
- for(int i=1;i<=n;i++)
- {
- if(nrmagic(i,p,q))
- {
- k++;
- cout<<i<<" ";
- }
- }
- cout<<k;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement