Show all threads Hide all threads Show all messages Hide all messages |
Runtime error(access violation) | Mithun Saha | 1083. Factorials!!! | 23 Jul 2017 21:57 | 4 |
#include<stdio.h> #include<stdlib.h> #include<string.h> int main() { long int n,k,val,fact=1,coeff=0;
char ch[24],*num,*excl;
gets(ch);
num=strtok(ch," "); n=atoi(num);
excl=strtok(NULL,NULL); k=strlen(excl);
while(coeff*k<n) { val=n-coeff*k; fact=fact*val; coeff++; }
if(n%k!=0) fact=fact*(n%k); else fact=fact*k;
printf("%ld",fact);
return 0; } Hi! I am getting runtime error(access violation) although the solution seems to work for different set of inputs. Please help me out! http://ideone.com/1tNjl7I have corrected your solution. Even if fix Access violation, You are just WA#5 (Because of a logic error) Edited by author 21.07.2017 00:59 Hi Mahilewets! Thanks a lot! I did correct the "Runtime error" but was getting a "Wrong answer" error due to the error in logic in the while condition. Your's is the right one. Just a query though(pardon my ignorance as I am new to this kind of stuff). How do you find the test cases for each problem apart from the one already given? |
Should we multiply by k or n%k if (n - i*k) equals k or n%k ? | Simoren | 1083. Factorials!!! | 5 Apr 2017 22:28 | 3 |
Hello, Should we multiply by k or n%k if (n - i*k) equals k or n%k ? Which sample is correct? Sample 1 8!! = 8 *(8-2)*(8-4)*(8-6)*2 Sample 2 8!! = 8 *(8-2)*(8-4)*(8-6) |
WRONG TEST 15!!! => БЕРИТЕ МАССИВ CHAR РАЗМЕРОМ 21 ЭЛЕМЕНТ))) | Ilya | 1083. Factorials!!! | 12 Jan 2017 00:21 | 1 |
С 20 не проходит 15 тест!!! |
WA test 10 C++ | TIU_Sarexer | 1083. Factorials!!! | 26 Oct 2016 21:47 | 1 |
#include <iostream> #include <string> using namespace std; int main() { int num, res; string c, b = "!", a = "!"; cin >> num >> c; res = num; int sign = 0; for (int i = 1; b <= c; i++) { b = b + a; sign = i; } if (num%sign != 0) { for (int i = 1; i*sign < num; i++) { res = res * (num - i*sign); } res = res *(num%sign); } else { for (int i = 1; i*sign < num; i++) { res = res * (num - i*sign); } } cout << res; return 0; } |
LOL!!! WA #1 but works correctly on my computer | Son1G | 1083. Factorials!!! | 15 Sep 2016 18:45 | 4 |
Problem is input of data! How should i fix it? Code: #include <iostream> #include <cstring> #include <string> using namespace std; int n, k; string s; int main() { cin >> n; cin >> s; int i; i=0; k=0; while(s[i]=='!') { k++; i++; }
long long a, temp;
a=1; i=0; if(n%k!=0) { while(temp!=n%k) { temp=n-i*k; a*=temp; i++; } } else if(n%k==0) { while(temp!=k) { temp=n-i*k; a*=temp; i++; } }
cout << a << endl;
system("pause"); return 0; } try to delete system("pause") may be it puts some text into stdout > In this program we have to do special handling of big integer variables Are you sure? 20! ~= 2E18 signed long long limit = 2^63-1 ~= 9E18 P.S. Article http://www.techcrashcourse.com/2015/05/c-programming-language-data-types.html is ... weird. Table is for some 16-bit compiler. Typical compilers now are 32bit - 64bit. No long long at all in the table. Long double - 10 bytes and bigger rabnge or the same range with double so 8 bytes? Edited by author 15.09.2016 18:57 |
can't go past test # 3 | nushrat | 1083. Factorials!!! | 6 Aug 2016 07:38 | 1 |
Am I making it too complicated ? can anyone tell me what's wrong with the logic ? 9 !! works ok ............. #include "stdafx.h" #include <iostream> #include <string> using namespace std; int main() { int n; string marks; int output = 1; cin >> n >> marks; int k= marks.length(); int until = n / k; if (n % k != 0) { for (int i = 0; i <= until; i++) { output *= (n - i * k); } output *= (n % k); } else if (n % k == 0) { for (int i = 0; i < k; i++) { output *= (n - i * k); } output *= k; } cout << output << endl; return 0; } Edited by author 06.08.2016 07:38 |
C++ Test | Qussy | 1083. Factorials!!! | 26 Jul 2016 12:05 | 1 |
never mind... Edited by author 28.07.2016 07:32 |
WA #5 | Landsknecht | 1083. Factorials!!! | 19 Jul 2016 15:32 | 1 |
WA #5 Landsknecht 19 Jul 2016 15:32 Could anybody give me this test please? Other tests are welcome as well :) Edited by author 19.07.2016 15:33 |
No subject | dimaa | 1083. Factorials!!! | 5 Jul 2016 21:04 | 1 |
Edited by author 05.07.2016 21:07 |
Please help me!How to solve this problem about it's limited time. | Hunter | 1083. Factorials!!! | 27 Apr 2016 10:15 | 2 |
import java.util.Scanner; public class Factorials { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); String k = in.next(); char a[] = k.toCharArray(); int length = a.length; function(n, length); in.close(); } private static void function(int n, int length) { int t = n % length; int c = (t == 0 ? length : t); int sum = n; for (int i = 1;; i++) { sum = sum * (n - i * length); if ((n - i * length) == c) { System.out.println(sum); break; } } } } If k > n then answer is n. Try "5 !!!!!!" |
Тест №8. Какой должен быть ответ? | Ananstasya | 1083. Factorials!!! | 27 Mar 2016 02:17 | 2 |
Тест №8. Какой должен быть ответ? Ни у кого нет тестов (кроме тех, кто создавал задачи и соответственно тесты). Мы можем только догадываться какой может быть тест № а , если смотреть на каком тесте валится наш код. В общем методом подбора |
test case | Abdullah Aziz Shakkhor | 1083. Factorials!!! | 3 Mar 2016 02:51 | 1 |
test case Abdullah Aziz Shakkhor 3 Mar 2016 02:51 |
Why do I get "Time Limit Exceeded"?. Any advise to improve my algorithm? | Jay | 1083. Factorials!!! | 19 Sep 2015 06:06 | 1 |
public class Factorials { public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String str = in.readLine(); StringTokenizer st = new StringTokenizer(str, " ");
int n = Integer.parseInt(st.nextToken()); int k = st.nextToken().length(); if (n >= 1 && n <= 10) { if (k >= 1 && k <= 20) { int limite= n % k, total = n, res= 0, i = 1; do { res= (n - (k * i)); if (res== 0) { System.out.print(total); return; } total *= res; i++; } while (res!= limite); System.out.print(total); } } } } Edited by author 19.09.2015 06:20 |
Why 9 !! is 945? | tigergr | 1083. Factorials!!! | 25 Aug 2015 20:37 | 3 |
According to input data 9!! = 9(9-1*2)(9-2*2)(9mod2) = 9*7*5*1=315 Edited by author 04.06.2015 18:13 Edited by author 04.06.2015 18:13 You forgot the multiplication with 3. 9 !! = 9(9-1*2)(9-2*2)(9-3*2)(9-4*2) = 9 * 7 * 5 * 3 * 1 = 945 The formula presented in the text has some "...", meaning that the product continues until the last member is either n mod k (in case n doesn't divide k) or k (in the other case). it will minus(-) what your input in string.... like you input (!!!) and enter 9,,,so there 9-3=6 then 6-3=3 then 3-3=1 so 9*6*3*1=162 so that's why u can solve this by 9 !!==> 9-2=7,7-2=5,5-2=3,3-2=1; so 9*7*5*3*1=945. that's it |
problem name : scholarship(2056) | MD.AL AMIN | 1083. Factorials!!! | 14 Jun 2015 21:51 | 1 |
why wrong ans test case # ?? Plzzz help my code: #include<bits/stdc++.h> using namespace std; int main() { int a[12],n,i; //int n,i; float res,sum=0; cin>>n; for(i=0; i<n; i++) { cin>>a[i]; sum+=a[i]; } res=(float)sum/n; if(res==5) printf("Named\n"); else if(res>=4.5&&res<5) printf("High\n"); else if(res>3&&res<4.5) printf("Common\n"); else printf("None\n"); return 0; } |
So stupid ... | baldman88 | 1083. Factorials!!! | 6 May 2015 13:08 | 3 |
Sorry for my english. First of all check the value of k: 0 < k < n. If False, then the result is n, otherwise -- use formulas. I saw your recent topic, so maybe someone will answer MY Q here (haha). Guys, help me to understand. I see 'n!!…! = n(n−k)(n−2k)…(n mod k)', between '-' sign and 'k' IS value here(which changes from 0...2...X . I used X, 'cause I dont know, TO WHICH number should this value change (of course 'k' or 'n'), tell me to which and why ? Actually, I think this task isn't formalized as shoud be(tell me if i'm wrong please). Thanks, you're right about that ... so stupid. Edited by author 06.05.2015 13:09 |
1083__ | Konjoh Elvis | 1083. Factorials!!! | 19 Apr 2015 19:56 | 1 |
1083__ Konjoh Elvis 19 Apr 2015 19:56 Can k be gretter than n if possible what should we do in this case? |
Ошибка в тестах. | Evgeniy | 1083. Factorials!!! | 4 Feb 2015 16:43 | 1 |
Если изменить правило 2(если n делится на k) и вместо k умножить на 1, то все заработает. Определение 1. n!!…! = n(n−k)(n−2k)…(n mod k), если n не делится на k; n!!…! = n(n−k)(n−2k)…1, если n делится на k (знаков ! в обоих случаях k штук). |
very easy solution on Java | Evgeniy[VVV] | 1083. Factorials!!! | 16 Nov 2014 15:15 | 2 |
it's very simple,especially on java. |
No subject | Platt96 | 1083. Factorials!!! | 24 Oct 2014 17:23 | 2 |
Если k>n что будет выводить? |