Page 6 (source removed after AC) Edited by author 23.01.2015 06:01 Resolved issue. Hints for those who look at this for reference. While this may not be the most elegant solution, it works. Make sure that: - Large values work. Try to imagine how many digits your solution could be composed of... - Values that may result in a legal (0-9) divisor at first, followed by a prime number... - As stated before, 0 and 1. Remember it's the LEAST positive integer... Edited by author 23.01.2015 06:00 New tests have been added. All accepted solutions have been rejudged. 886 authors have lost AC. such a fool i was 5 years ago... and test is so simple :) Edited by moderator 23.08.2020 01:25 For example I'm going to enter "40". Your program shows "2225", though should have been seen something like "58". If I understood the clause right. Program must return Q=10 if N==0 and Q=1 if N==1. This is not what one should expect from the description of the problem. what should it return for N = 5? Is Q 5 or 15 then? Thanks Your task is to find the MINIMAL positive integer number Q... If n=5 you must print 5, no 15. 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 Обратите внимание на результат при N = 1000000000. А точнее на его размер 555555555888 в 32 бита он не поместится. 8 тест из-за этого выдает "Wrong answer". I don't know what my code's problem is. I have tested all input and got correct output, however I got WA#1 when summitting. Please help me!! Edited by moderator 23.08.2020 01:19 tell me, please, what input in test 5. use long long int instead of int , it may help.. if N=1 000 000 000 i have Q->555555555888. And as i read it's right answer. Edited by author 06.01.2013 05:07 To whom it may concern! There were sovlved two different programms. The first one, when there is given an input 120 the output is 358; the second output is 456. But both of them were accepted. Could you explain to me why this that, if you please? It's because of weak tests :D var a:array[1..10000] of Longint; b:array[1..10000] of string; min,c,n,i,j,k:Longint; s:string; begin read(n); for i:=2 to n-1 do begin if n mod i=0 then j:=i; if (j<>0) and (j<10) then begin k:=k+1; str(j,b[k]); str(trunc(n div j),s); b[k]:=b[k]+s end; end; for i:=1 to k do val(b[i],a[i],c); min:=a[1]; for i:=1 to k do if min>a[i] then min:=a[i]; if min<>0 then write(min); if j=0 then write('-1'); end. i try to find but i don't know where i'm wrong ?? Who know test 10, please tell me !!! Tks very much I use long long int with MinGW and have right answer for the input of 1000000000.Why it is still wrong? Here is my C code. #include<stdio.h> #include<math.h> #include<stdlib.h> int sum(int a); int main() { int count[10],i,j,base=0; //use count[2] to count [9] to store the number of digits long long int n,product=0; for(i=0;i<10;i++) count[i]=0; scanf("%lld",&n); if(n==1) printf("%d\n",1); else if(n==0) printf("%d\n",10); else{ for(i=9;i>1;i--){ while(n%i==0){ n/=i; count[i]++; } } if(n==1){ /* for(i=2;i<=9;i++){ for(j=0;j<count[i];j++){ printf("%d",i); } } */ for(i=9;i>=2;i--){ product=product+i*sum(count[i])*pow(10,base); base=base+count[i]; } printf("%lld",product); } else printf("%d",-1); printf("\n"); } system("pause"); return 0; } int sum(int a) { int term=1,i,result=0; for(i=0;i<a;i++){ result+=term; term*=10; } return result; }
The idea is to find divider for n in set between 2 and 9. If there is no such dividers we'll have answer -1. If yes, we divide n by this divider and do it again, until n isn't equal 1. Realization: #include <iostream> #include <math.h> #include <cstdio> #include <string.h> using namespace std; void main(void) { long long int n; cin>>n; if (n==0) { cout<<"10" ; return; } if (n==1) { cout<<"1"; return; } int *a = new int[14]; for(int i = 0;i<14;i++) { a[i] = 0; } int counter = 13; while(n>1) { for(int j = 9;j>=0; j--) { if (j==1) { cout<<"-1";
return; } if (n%j==0) { a[counter] = j; counter--; n/=j; break; } } } for(int i = counter+1 ;i<14;i++) { cout<<a[i]; } return; } Sorry, for my English and for some unnecessary includes or code=) N=12 Q=26 not 34. 34 or 26 But 26 is less than 34 Edited by author 24.11.2012 23:51 #include <iostream> #include <cmath> #include <vector> #include <algorithm> using namespace std; int main(int argc, char** argv){ long long int n; cin>>n; vector<char> v; if(n == 1){ cout<<1; return 0; } else if(n == 0){ cout<<10; return 0; } int cur = 9; while(n!=1){ bool flag = false; for(; cur>=2; --cur){ if(n/cur*cur==n){ flag = true; v.push_back(cur); n = n/cur; cur = 9; } } if(!flag){ cout<<-1; return 0; } } sort(v.begin(), v.end()); long long int a = 0; for(int i = 0; i<v.size(); i++){ a = a*10 + v.at(i); } cout<<a; } now i Have AC. Thx for all! Edited by author 22.11.2011 01:06 Edited by author 22.11.2011 01:06 My program is Accepted with int N. ))) In gcc (the C compiler) the int type has 32bit, for the 16bit version use short. Cheers Edited by author 04.11.2011 22:17 function son(a:integer):integer; var i,k:integer; begin k:=0; while a>0 do begin a:=a div 10; k:=k+1; end; son:=k; end; var a:longint; x,y:array[1..10000] of integer; i,j,k,b,d:integer; begin read(a); k:=0; for i:=trunc(sqrt(a)) downto 1 do begin if a mod i=0 then begin k:=k+1; x[k]:=i; k:=k+1; x[k]:=trunc(a/i); end; end; i:=1; j:=1; while i<k+1 do begin b:=trunc(exp(son(x[i+1])*ln(10))); y[j]:=x[i]*b+x[i+1]; i:=i+2; j:=j+1; end; k:=j-1; j:=y[1]; d:=trunc(1*exp(son(a)*ln(10))+a); for i:=1 to k do if ((j>y[i])and(y[i]<>d)) then j:=y[i]; if a=0 then write(10) else if a=1 then write(1) else if a=45 then write(335) else if (d=j) then write(-1) else write(j); readln; readln; end. |
|