|
|
How is it POSSIBLE to find 42 test case? It seems like everything should work fine.. OK, found my mistake. 777&222 would be very helpful test cases) 150 : 556 Edited by author 14.06.2020 17:05 There is another interesting test case that might be a cause of WA8. Try 12, and the right answer should be 26. Edited by author 15.03.2024 16:13 #include<bits/stdc++.h> using namespace std; bool isPrime(int n) { if(n!=2&&n%2==0)return false; if(n<2)return false; for(int i=3;i<=sqrt(n);i+=2) { if(n%i==0)return false; } return true; } int main() { int n; cin>>n; int x=9,r; if(n==1)cout<<1<<endl; else if(n==0)cout<<10<<endl; else{ vector<int>v; while(1) { if(n%x==0) { if(isPrime(n)==true) { if(n>9){cout<<-1<<endl;return 0;} } n=n/x; if(x==1)break; v.push_back(x); } else { x--; } } for(int i=v.size()-1;i>=0;i--) { cout<<v[i]; } cout<<endl; } } The authors should've mentioned these in the question. Like if q is 0 then you should print 10 but if it is any number between 1 to 9 then you should print that number only, i.e. 2 for 2, 4 for 4 not 14 for 4. Thanks, that saved me a lot of time. I was printing 0 for 0. Which makes sense in my opinion. The output needs to be sorted in ascending order(!) so for test number 5: 45 the correct answer is 59 (5*9) and 95 (9*5) will be rejected. Hope this helps someone. Mine does return 59 yet its said to be WA simple anwser: WA Edited by author 13.11.2022 12:39 What is the mistake? n = int(input()) a = [] for i in range(1, n+1): if n % i == 0: a.append(i) if n == 1: print("1") exit(0) if n == 0: print("10") exit() if len(a) > 2: for i in range(len(a) - 1): if a[i] * a[i + 1] == n or a[i]*a[i] == n: if a[i] * a[i + 1] == n: s = "".join(sorted(str(a[i])+str(a[i+1]))) print(s) else: print(a[i], a[i], sep="") else: print("-1") Whats wrong with anything here? #include <bits/stdc++.h> using namespace std; using ll=long long; using ui=unsigned int; int main() { //ios::sync_with_stdio(0); //cin.tie(0); ll n;cin>>n; if(!n){ cout<<10; return 0; } else if(n<10){ cout<<n; return 0; } vector<int>v; ll l=n; for(bool q=1;q;){ q=0; for(ll i=9;i>1;i--){ if(l%i==0){ l/=i; v.push_back(i); q=1;
} } } v.push_back(l); sort(v.begin(),v.end()); if(v[0]==1)for(int i=1;i<v.size();i++)cout<<v[i]; else cout<<-1; return 0; } Ok later I figured out that instead of dividing by all the numbers consecutively, dividing by the current factor between 2 to 9 repeatedly until it isn't a factor provides the fewest digits. For example, input 1000000 gives 245555558 in the above program, whereas 2 and 4 could be replaced by 8 for better result. Edited by author 14.10.2022 13:41 if u have wa 44 just remove one in the cyclic factorization, if there is one. <=sqrt() + 1 -- bad <=sqrt() -- good I don't know the problem use std::io; use std::io::BufReader; use std::io::BufRead; fn minimal_product_digit(n: i64) -> i64{ if n == 0 {return 10}; if n < 10 { return n};
let f : Vec<i64> = vec![2,3,5,7]; let mut aux = n; let mut ret : Vec<i64> = Vec::new(); for i in f{ if aux % i== 0 { loop{ aux/=i; ret.push(i); if aux % i != 0 { break; } } } }; if ret.is_empty() || aux > 1 { return -1; }
match ret.iter().fold(0,|acc,elem| if *elem == 3{acc + 1} else {acc}) { 1 => { let index = ret .iter().position(|&x| x == 3).unwrap(); if index > 0{ ret.remove(index); let k = ret.get_mut(index - 1).unwrap(); *k = 6; ret.sort();
} } _ => () } let mut v : Vec<i64> = Vec::new(); for i in ret{ match i { 2 | 3=> match v.last_mut(){ None => v.push(i), Some(last) if i ==3 && *last == 2 => v.push(i), Some(last) => { let valor = *last; if (valor * i) < 10{ *last = valor*i } else{ v.push(i); } } } _ => v.push(i) } } v.sort(); v.iter().fold(0, |acc, elem| acc * 10 + elem) } fn main() { let mut line = String::new(); let mut stdin = BufReader::new(io::stdin()); stdin.read_line(&mut line).unwrap(); let lim = line.trim().parse::<i64>().unwrap(); println!("{:?}",minimal_product_digit(lim)); } can anyone tell me what is test case 13? i dont know why my code is failing test 4.can any body give me a series of test cases where this kind of program may fail. please help n=0 Answer 10 but i think if n<10 then least possible number will be n. your solution makes it 2 digit. The task is to find a minimal POSITIVE number, so 0 doesn't work. #include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { int Num = 0, ans = -2; cin >> Num; vector <int> fact; int n = 2; while (Num > 1) { if (n > 9) { ans = -1; break; } while (Num % n == 0) { Num /= n; fact.push_back(n); } n++; } sort(fact.begin(), fact.end()); if (n < 10 & ans != -1) { ans = 0; for (int i = 0; i < fact.size(); i++) { //ans += fact.at(i) * (i*10); cout << fact[i]; } } //cout << ans; } Hey! I solved this problem and here are some test that you may check for you solution: 0->10 1->1 2->2 3->3 4->4 5->5 6->6 7->7 8->8 9->9 10->25 11->-1 12->26 13->-1 14->27 15->35 16->28 17->-1 18->29 19->-1 20->45 21->37 22->-1 23->-1 24->38 25->55 26->-1 27->39 28->47 29->-1 30->56 31->-1 32->48 33->-1 34->-1 35->57 36->49 37->-1 38->-1 39->-1 40->58 41->-1 42->67 43->-1 44->-1 45->59 46->-1 47->-1 48->68 49->77 50->255 51->-1 52->-1 53->-1 54->69 55->-1 56->78 57->-1 58->-1 59->-1 60->256 61->-1 62->-1 63->79 64->88 65->-1 66->-1 67->-1 68->-1 69->-1 70->257 71->-1 72->89 73->-1 74->-1 75->355 76->-1 77->-1 78->-1 79->-1 80->258 81->99 82->-1 83->-1 84->267 85->-1 86->-1 87->-1 88->-1 89->-1 90->259 91->-1 92->-1 93->-1 94->-1 95->-1 96->268 97->-1 98->277 99->-1 100->455 Good Luck! I have checked for my solution. All done. But I have "Wrong answer" at test 8..... try this test: 732421875 result must be: 3555555555555 and this: 0 (result: 10) 1 (result: 1) Edited by author 15.06.2011 14:32 Shouldn't the test value for 1 be 11 and so on for single digit numbers? Edited by author 17.08.2020 15:23 Edited by author 17.08.2020 15:23 Edited by author 17.08.2020 15:23 what will the output if input = 1 or 0 and why? if n=0 then q=10 if n=1 then q=1 Should be 11 though, I don't know why authors decided on 1. The solution requires a product of digits. 1 by itself isn't a product at all. Edited by author 19.05.2020 18:51 This problem can be solved using greedy technic. Method is to divide the given number from 9 to 2. Each time we will continue to divide and update the number as we go. We will keep dividing N with the same number utill its impossible to do so.And for each division we will save the number which was divisible by given number. And by "save" i mean pushing the number in a stack or a in a vector or an array. If you are using other than stack you might print out the numbers in a reverse manner. And when we are getting "-1"? I already wrote that, we keep updating the number. so after we pass the 9 to 2 loop, we should be left with a value of 1 in the variable N ( given number ). Incase N!=1 we are just printing "-1". For the case N=1 or N=0? for the case 1 you should just print "1" and for the case 0 print "10", we can not print 01 since this refers to number, 1. If you have problem understanding what i have just written or for better understanding, give this a go : https://ideone.com/709cog Edited by author 21.02.2020 00:34 Edited by author 21.02.2020 00:38 Edited by author 21.02.2020 00:41I have tried everything. Here are some testcases from my algorithm: 0: 10 1: 1 2: 2 3: 3 4: 4 5: 5 6: 6 7: 7 8: 8 9: 9 10: 25 12: 26 14: 27 15: 35 16: 28 18: 29 20: 45 21: 37 24: 38 25: 55 27: 39 28: 47 30: 56 Some big numbers: 16859136: 267778888 16875000: 3555555589 16934400: 355778889 16941456: 277777789 17006112: 48999999 17010000: 555567899 17146080: 256778999 17150000: 1555557778 17203200: 155788888 17210368: 177777888 17222625: 355579999 17280000: 555568889 17287200: 455777789 17294403: 177777777 17360406: 67799999 17364375: 555577799 17418240: 256788899 17496000: 355588999 17500000: 4555555578 17503290: 257777999 17561600: 455777888 17578125: 5555555559 17635968: 67889999 17640000: 555577889 17647350: 556777777 17694720: 256888889 17714700: 255699999 17718750: 2555555799 long long int minimoentero3(long int num) { long long int nf=result; return nf; } int main() { long int n; cin >> n;
cout<<minimoentero3(n); <- Here the result is sent. } Edited by author 26.10.2017 18:28 test 17294403: 177777777 17294403 != 177777777 (5764801) also 77777777 < 177777777 right answer for this test 377777777 Factorize (in 1..9 figures) the N and then reduce the resulting number of figures. For each i = 9 to 2, repeatedly divide n by i until it cannot be further divided or the list of numbers from 9 to 2 gets finished. Also, in the process of division push each digit i onto the stack which divides n completely. After the above process gets completed check whether n == 1 or not. If not, then print “-1”, else form the number k using the digits from the stack containing the digits in the same sequence as popped from the stack Edited by moderator 23.08.2020 01:12 Did you try some big prime number? Like 777777773. Anybody can help me with TEST #10. Just give me an example Thank you very much. 222 ans is--> -1 bcuz 222/6= 37 ;but 37 is prime so ans -1 |
|
|