Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**Se citeste de la tastatura un numar natural X.
- Sa se construiasca toate matricele patratice cu valori in multimea
- cifrelor lui X, care au proprietatea
- ca pe fiecare linie elementele sa fie distincte, iar suma valorilor
- de pe fiecare coloana
- este un numar cu numar par de divizori.
- */
- #include <iostream>
- #include <fstream>
- using namespace std;
- int x,n;
- int a[100][100];
- ofstream fout("date.out");
- void afisare()
- {
- for(int i=1;i<=n;i++)
- {
- for(int j=1;j<=n;j++)
- fout<<a[i][j];
- fout<<endl;
- }
- fout<<endl;
- }
- int p_c(int x)
- {
- if(x<10)
- return x;
- return (x/10);
- }
- int nr_div(int x)
- {
- int nr=0;
- for(int d=1;d*d<x;d++)
- {if(x%d==0)
- nr+=2;
- if(d*d==x)
- nr++;
- }
- return nr;
- }
- void back(int l,int c,int S)
- {
- if(l==n+1)
- afisare();
- else
- if(c==n+1&&nr_div(S)%2==0)
- back(l+1,0,S);
- else
- for(a[l][c]=p_c(x);a[l][c]<=x%10;a[l][c]++)
- back(l,c+1,S+a[l][c]);
- }
- int main()
- {
- cin>>x>>n;
- back(1,1,0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement