1) множитель не может быть отрицательным 2) умножать надо не по количеству восклицательных знаков а пока i*k < n 3) если ( n - i*k ) равно n % k или ( n - i*k ) равно k значит мы посчитали факториал ( то есть надо больше ничего с числом не делать ) 4) n и k от 1 до 20 5) составители задачи тупые мудаки I would say the same ("tupoi mudak" (*)) about the author of the post. Problem statement is more than clear: "n!!…! = n(n−k)(n−2k)…(n mod k)", "X mod Y — a remainder after division of X by Y", then even example is given: "10 mod 3 = 1". If after all this you couldn't derive that "1) множитель не может быть отрицательным" - then you're really (*) "3) если ( n - i*k ) равно n % k или ( n - i*k ) равно k значит мы посчитали факториал ( то есть надо больше ничего с числом не делать )" - just copy from the problem statement "4) n и k от 1 до 20" - just wrong (n <= 10, as, again, given in the statement) What is test #1?? maybe you divide a number by zero to get that runtime error the product is : n*(n-k)*(n-2*k)... till---> k if divisible by k, i.e. the last non zero value of n OR n(mod)k which is again the last non zero value of n. You don't have to multiply it with k or n mod k again. I have 1 test runs but on the server WA test 1!!??? program pro; var n,k,t:byte; s:string; sum:integer; BEGIN read(n,s); t:=1; k:=length(s)-1; if n mod k=0 then begin sum:=n; while n-t*k>0 do begin sum:=sum*(n-t*k); t:=t+1; if sum*(n-t*k)<0 then break; end; sum:=sum*k; end else begin sum:=n; while n-t*k>0 do begin sum:=sum*(n-t*k); t:=t+1; if sum*(n-t*k)<0 then break; end; sum:=sum*(n mod k); end; write(sum); END. 9 !! My program write 945 and why WA 1?????? Каким должен быть ответ ,если значения n или k не валидны? Например, если не указать k. Или ввести значения, не попадающие в диапазон? RTFM: http://acm.timus.ru/help.aspx?topic=judge "Input data in the test cases always satisfy the constraints described in the problem statement. You don’t need to verify these constraints in your solutions." I think description of the problem should state that "long numbers have to be used". So for this problem use long integers. I think description of the problem should state that "long numbers have to be used". So for this problem use long integers. Определение: n!!…! = n(n−k)(n−2k), где k - количество знаков "!". При расчете на любом этапе не должно получатся отрицательного числа. И все. Я только с таким условием получил "Accepted". Спасибо. Условие было действительно странное и непонятное, а, как показала практика, так ещё и неправильное. var f,i:longint; k:1..20; n:1..10; s:string; begin readln(n); read(s); f:=1; k:=length(s); for i:=0 to (n div k)-1 do begin f:=f*(n-i*k); end; writeln(f); end. Nargiza sizning xatoyingiz sonni va faktarialni ajratib olishda, va bundan tashqari hisoblash tsiklida n dan 1 ga tomon qadam k shaklida oling ya'ni.....qanday hisoblash tsiklida n dan 1 ga tomon qadam k shaklida olinishi kerak sizda menimcha kiritish jarayonida raqam(n) va undov(!) orasida probel(_) qo'ymasdan yozganda xato ishlashi mumkin. shunda undovlarni ham raqam sifatida o'qib s ni uzunligi 0 ga teng bo'lib qoladi. shuning uchun n/l(n bo'lingan s ning uzunligi) n/0 bo'lib qolyapti shunda sizga Crash (integer division by zero) ashibka beryapti #include <iostream> using namespace std; int main() { int n,t,s; cin>>n; char k[20]; gets(k); s=n; t=n%(strlen(k)-1); if(t!=0) while(n>t) { n=n-(strlen(k)-1); s*=n; } else while(n>(strlen(k)-1)) { n=n-(strlen(k)-1); s*=n; } cout<<s<<endl;
return 0; } Here's my code,and I don't know what's wrong with it? #include<iostream> using namespace std; char s[25]; int main() { __int64 n,k; while(scanf("%I64d%s",&n,s)!=-1) { k=strlen(s); if(n<=k) { printf("%I64d\n",n); } else { __int64 sum=1,i; if(n%k==0) { for(i=n;i>=k;i-=k) sum*=i; } else { for(i=n;i>=n%k;i--) sum*=i; } printf("%I64d\n",sum); } } return 0; } Edited by author 15.06.2013 12:54 Edited by author 15.06.2013 12:56 var n,i,j,ans:Integer; k:integer; kvoskl:string; begin ans:=1; j:=1; read(n,kvoskl); k:=length(kvoskl); i:=n; if n mod k = 0 then begin while i>=k do begin ans:=ans*i; i:=n-j*k; inc(j); end; end else begin while i>=n mod k do begin ans:=ans*i; i:=n-j*k; inc(j); end; end; writeln(ans); end. what`s wrong? 9 !! - ввод 945 - вывод пишет wrong answer var n,i:integer; res:longint; k:string; begin read(n,k); i:=0; res:=1; if n mod length(k)=0 then repeat res:=res*(n-i); inc(i,length(k)); until n-i=length(k) else repeat res:=res*(n-i); inc(i,length(k)); until n-i=1; writeln(res); end. как решил mne toje takoy: --------------------- var x,s:string; s1,j,i,c,l:longint; begin read(x); repeat i:=i+1; s:=s+x[i]; until x[i]=' '; l:=length(x)-i; val(s,s1,c); j:=s1; repeat j:=j-l; s1:=s1*j; until j<=1; write(s1); end. It works but here i get Compilation Error #include <iostream> using namespace std; int main(){ int num, val, numMod; string nFuc; cin >> num >> nFuc;
int i = nFuc.length();
int mod = num % i; if(mod != 0){ numMod = num; val = numMod; while(numMod != mod){ numMod -= i; val *= numMod; } }
else if(mod == 0){ numMod = num; val = numMod; while(numMod > i){ numMod -= i; val *= numMod; } }
cout << val << endl; } #include <stdio.h> int fact(int n, int k){ int res = 1; if (n == 0) return res; while (n > k) { res *= n; n -= k; } if (n % k) res *= (n % k); else res *= k; return res; } int main () { char sym; int n = 0; int symCount = 0; scanf("%d ", &n); while (scanf("%1[!]", &sym) == 1) { symCount++; } printf("%d\n", fact(n, symCount)); return 0; } I don't know why this error occurs, even the execution time is less then the time limit???? Please help me out?
what's wrong? #include <stdio.h> #include <conio.h> main() { int a,len=0,t=1; char b[20]; scanf("%d%s",&a,b); len = strlen(b); for( ; a > 1 ; a -= len ) t *= a; printf("%d",t); return 0; }
int result = 1; for (int i = n; i > 0; i -= k) result *= i; printf("%d\n", result); please anyone help me if accepted . it gives me wrong answer on test 1 and as i suppose in test 1 k=0 and i don't know what write :) thanks... int result = 1;
for (int i = n; i > 0; i -= k) result *= i; plz explain what this test no shows ? Edited by author 06.08.2012 17:08 |
|