- /****************##### بِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيم #####*******************
- __________________________________________________________________________
- ###################### Ya-Seen Arafat(ACWizard) #########################
- ###################### UAP-CSE-33B #########################
- *************************************************************************/
- #include <bits/stdc++.h>
- #define sc(n) scanf("%d", &n)
- #define S 10003
- using namespace std;
- typedef long long LL;
- int check[10], cn;
- struct data{
- int first, second;
- }arr[S];
- void check_digit(int NN){
- cn = 0;
- while(NN > 0){
- int mod = NN%10;
- if(!check[mod])cn++, check[mod] = 1;
- NN /= 10;
- }
- }
- int cmp(data a, data b){
- if(a.first == b.first)return a.second < b.second;
- return a.first < b.first;
- }
- void Do(){
- int n, d, bl = 0;
- while(sc(n) == 1){
- if(n == 0)break;
- int k = 0;
- memset(arr, 0, sizeof(arr));
- for(int i = 98765; i >= 10000; i--){
- memset(check, 0, sizeof(check));
- check_digit(i);
- if(cn < 5)continue;
- if(!(i%n)){
- int N = i/n; cn = 0;
- d = log10(N)+1;
- if(d >= 4){
- check_digit(N);
- if(!check[0] && cn == 4 && d == 4){
- arr[k].first = i;
- arr[k++].second = N;
- }
- if(cn == 5){
- arr[k].first = i;
- arr[k++].second = N;
- }
- }
- }
- }
- sort(arr, arr+k, cmp);
- if(bl)puts(""); bl = 1;
- if(!k)printf("There are no solutions for %d.\n", n);
- else{
- for(int i = 0; i < k; i++){
- int ll = log10(arr[i].second);
- if(ll == 4)printf("%d / %d = %d\n", arr[i].first, arr[i].second, n);
- else printf("%d / 0%d = %d\n", arr[i].first, arr[i].second, n);
- }
- }
- }
- }
- int main(){
- ios_base::sync_with_stdio(0); cin.tie(0);
- #ifndef ONLINE_JUDGE
- ///freopen("inp","r",stdout);
- ///freopen("contest.txt","w",stdout);
- #endif
- Do();
- return 0;
- }
Friday, June 5, 2015
UVa - 725 - Division
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment