Can Anyone be kind enough to explain this ques to me? I'll be grateful to you.. 1) 11 !!!! - 231 2) 13 !! - 135135 3) 36 !!!!!! - 33592320 4) 7 !!!!! - 14 5) 21 !!!!!!! - 2058 and DONT forget that (n mod k) or k is not the last multiplayer rus: не путайте, (n mod k) или k не являются последним множителем!! "не путайте, (n mod k) или k не являются последним множителем!!" Серьзно? Условие максимально тупо написано... //Don't ask me. I don't know. Just work. If anybody can tell me why for (int i = k + 7; i >= 0; i--) and why we needn't n%k - Please, tell! I don't understand. using System; namespace ConsoleApp32 { class Program { static void Main(string[] args) { string[] vvod = Console.In.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); int n = int.Parse(vvod[0]); string k1 = vvod[1]; int k = k1.Length; int q = 1; for (int i = k + 7; i >= 0; i--) { int t; t = n - i * k; if (t > 0) q *= t; } Console.WriteLine(q); } } } Edited by author 13.01.2018 23:49 because we have more than 1x! (minimum 2) and less or exactly 9 (because we have 9 numbers 2...10 and it nevermind if we have more !...! than 9). so we have k = 9-2 =7 (maximum) if we use % and the number of '!' is > 10 we have wrong answer, because we have zero: x%y=0 Edited by author 19.03.2023 19:49 For n = 10 and k = 20, what should be the output? Well, obviously it's not 0! For this test case (n=10, k=20) answer is equal to 10. why? Can you please explain? be attentive with loop (while)! we know formule n - x * k =) and in depends of number parity condition will be >= (ex. [n - x * k >= n mod k] or [n - x * k >= k]). Good luck!) Edited by author 19.01.2023 16:23 what is wrong with my program? I used Python code below: n = input() list = n.split() n = int(list[0]) k = len(list[1]) if (n < k): p = k else: p = n
i=2 num = n - k if (n>=1 and n<=10) and (k>=1 and k<=20) and (num > 0): if((n%k) == 0): while(num>k): p = p*num num = n-i*k i=i+1 p = p*k else: while(num>(n%k)): p = p*num num = n-i*k i=i+1 p = p*(n%k) print(p) Edited by author 17.06.2022 20:39 #include<bits/stdc++.h> using namespace std; int solve(int n, string k){ int ans=k.size(); if(n>=1){ return n*solve(n-ans); } else{ return 1; } } int main() { int t,n; string k; cin>>n; cin>>k; int result=solve(n,k); cout<<result<<endl; return 0; } тест 1: n=9 k=2 тест 2: n=1 k=1 тест 3: n=10 k=1 тест 4: n=8 k=1 тест 5: n=10 k=2 тест 6: n=7 k=2 тест 7: n=1 k=2 тест 8: n=2 тест 9: n=10 k=5 тест 10: n=9 k=5 n=3,4,5,6 не встречается... тест 8 - к по условию не может быть меньше 1. В единственной строке сначала дано целое число n, 1 ≤ n ≤ 10, затем ровно один пробел, затем k восклицательных знаков, 1 ≤ k ≤ 20. про значение К в этом тесте не известно а какой ответ на 9 тест? 1) 50 Очень интересно а как вы эти тесты извлекли? Edited by author 10.02.2010 23:53 Какой ответ на тест 5? 945? Тест 8 - просто супер. Явная неучтенка. И сколько еще таких тестов? Просто офигенная постановка задачи. Edited by author 16.04.2011 19:50 Скажите,пожалуйста, какой должен быть ответ в тесте номер 8? Я уже пробовала,чтобы программа не пропускала такие варианты с помощью repeat, пробовала ставить в таком случае ответ 1, ответ 0, ответ - само число. Ничего не получается! Edited by author 29.07.2014 13:12 Тест 10: 9 !!!!! = 9(9-5)(9 mod 5) = 9*4*4 = 144 Почему вылазит неправильный ответ?! N mod K — это последний больший нуля элемент ряда N - XK. В данном случае этот элемент первый и он же последний, не нужно умножать на него два раза. Иными словами, мы вычитаем K от исходного числа, и умножаем на получившееся, и повторяем так до тех пор, пока получившееся число не станет нулём или меньше. Еще вопрос: 2 !!! = ? 2 или 4? и какие вводные 11-го теста? Меня очень интересует как в примере 9 !! получилось равным 945 если разбирать описание задачи то получим: n = 9 k = 2 n mod k = 1(есть остатое от деления) тогда получаем 9!! = 9*(9-2)*1 = n(n-k)(n mod k) = 9*7*1 = 63 Ну откуда 945 невкурю???? This problem is easily solving without any precalcing or info about tests. Not more than 15-20 lines of code. I did not ask about the problem of solving the problem. I asked about the correctness of my reasoning, I can not right in the calculation of 9 !! 9 !! i 1) n:=9*(9-2) 2)n:=63*(9-4) 3)n:=315*(9-6) 4)n:=945*(9-8) This is correctness of your reasoning. In my program test 5 is correct, but system writed, that wrong. Answer - 7680 In my program test 5 is correct, but system writed, that wrong. Answer - 7680 All manual tests ok. Test 5 is also in error. I do not understand this... import java.util.*; public class Factor { public static void main(String[] args){ Scanner put=new Scanner(System.in); int n,k,fac; String ffc; n=put.nextInt(); ffc=put.next(); k=ffc.length(); fac=n; for(int i=1;i<(n/k);i++){ fac=fac*(n-(i*k)); } if(n%k!=0)fac=fac*(n%k); else fac=fac*k; System.out.print(fac); } } Edited by author 29.10.2012 17:37используя гамма функцию можно в одну строчку :) Застрял в тесте 8: #include<stdio.h> #include<string.h> int main(){ int n, i, l; char k[20]; scanf("%d%s", &n, k); l = strlen(k); int result = n; i = n - l; do{ result = result * i; i = i - l; } while (i > n % l); if (n == 1) result = 1; printf("%d", result); return 0; } Edited by author 02.12.2017 02:41 Edited by author 02.12.2017 02:41 Edited by author 25.07.2014 12:47 9 !! = 9*(9-2)*(9-2*2)*(9-2*2*2)....*1=9*7*5*3*1=945 Answers for numbers from topic: 1. 945 2. 1 3. 3628800 4. 40320 5. 3840 6. 105 7. 1 8. 2 (if in this case k = 1) 9. 50 10. 36 Моё нестандартное решение :) import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class proga { public static void main(String[] args) throws IOException { BufferedReader sc = new BufferedReader(new InputStreamReader(System.in)); String[] temp = sc.readLine().split(" "); int ch = Integer.parseInt(temp[0]); int len = temp[1].length(); int ost = ch%len; int result = ch; if(ost==0){ost+=len;} while(ch!=ost) { ch-=len; result*=ch; } System.out.println(result); } } а какой ответ на тест 5 ? what's the right answer for test 5 ? who knows ? can you give a hand pls тест 1: n=9 k=2 тест 2: n=1 k=1 тест 3: n=10 k=1 тест 4: n=8 k=1 тест 5: n=10 k=2 тест 6: n=7 k=2 тест 7: n=1 k=2 тест 8: n=2 тест 9: n=10 k=5 тест 10: n=9 k=5 n=3,4,5,6 не встречается... why wrong on test 5?? #include<iostream> //#include<string> using namespace std; int main() { int n; string s; cin>>n; cin>>s; int sum=n; int len = s.size(); //cout<<len<<endl; int i =1; while((n-i*len)>1) { sum*=(n-i*len); i++; } if(n%len!=0) cout<<(sum*(n%len))<<endl; else cout<<sum*len<<endl; return 0; } 8th test is 2 !! and the answer is 2 #include<bits/stdc++.h> using namespace std; int main() { int n; int mul = 1; string s; cin>>n>>s; int k = s.size(); if(n%k==0){ int in = n; int temp = k; while(1){ mul = mul*in; in = in - k; if(in==k){ mul*=in; break; } } } else{ int in = n; while(1){ mul = mul*in; in = in - k; if(in==(n%k)){ mul*=in; break; } } } cout<<mul<<endl; return 0; } What is test case 2? #I don't know why i start from lk+7. If anyone knew about that, please notify me. import sys n,k = sys.stdin.readline().split() n = int(n) lk = len(k) res = 1 for i in range(lk+7,-1,-1): t = n - i*lk if t>0: res *= t sys.stdout.write("%d\n"%res) Edited by author 16.07.2021 09:03 what is wrong? #include <iostream> #include <cmath> #include <map> #include <vector> using namespace std; int main() { int n; string str; cin >> n >> str;
int k = str.size(); int i = 0; int sum = 1; if(n % k == 0) { while(i != n / k) { sum *= n - k * i; i++; } } else { while(i != n / k + 1) { sum *= n - k * i; i++; } sum *= n % k; }
cout << sum << endl;
return 0; } Edited by author 31.12.2015 12:38 It would be great if you stop searching telepathists and show error message. Is it compilation error? Add "#include <string>" line. Is it WA? Strange. Code looks working. Is it any another error? Show it. WA #10 Some people suppose n can be 20 so int is not enough for sum. Try to use long long sum. WA #10 Test: 5 !!! answer 10, your answer 20 5!!! here k=3, 5 isn't divisible by 3 so you have to multiply 5%3=2 with 5*(5-3) so the answer is 5*2*2=20 #include<iostream> //#include<string> using namespace std; int main() { int n; string s; cin>>n; cin>>s; int sum=n; int len = s.size(); //cout<<len<<endl; int i =1; while((n-i*len)>1) { sum*=(n-i*len); i++; } if(n%len!=0) cout<<(sum*(n%len))<<endl; else cout<<sum*len<<endl; return 0; } A simple way to solve is to begin with a value x which going to depend whether n % k == 0. and increase it by k until it becomes n. and of course on each step multiply it to your sum which is initially 1. for n=2,k=3 ans=2*(2-3)*(2-6)*(2-9)*..... The author must include the condition that n>=k.. На Паскале не работает код если начать его так: read(n); read(s); (или readln(s)) n - longint, s - string Но если так: readln(s); А затем разрезать на n и s1, то всё ОК. Разве так и должно быть? a,b=input().split() n=int(a) k=len(b) temp=n t=k while temp-k>0: n*=(temp-k) k+=t print("%d"%n) import java.util.*; import java.lang.*; public class Factorial{ public static void main(String[] args){ Scanner cin=new Scanner(System.in); int n=Integer.parseInt(cin.next()); String k=cin.nextLine(); int j=k.length()-1; int sum=1; for(int i=n;i>0;i-=j){ sum=sum*i; } System.out.println(sum); } } using namespace std; #include<iostream> #include<string> #include<sstream> #include<ctype.h> void factorial(unsigned long n,unsigned long k); int main() { unsigned long counter=0; string s; unsigned long n; while(getline(cin,s)) { counter=0; string::size_type position,position2; position=s.find(' '); string num; for(int i=0;i<position;i++) { if(isdigit(s[i])) num+=s[i]; } stringstream ss(num); ss>>n; position2=s.find('!'); if(position2==position+1) { for(int i=position+1;i<s.size();i++) if(s[i]=='!') counter++; factorial(n,counter); } } } void factorial(unsigned long n,unsigned long k) { unsigned long res=1; int mod=n%k; unsigned long mul=n; if(mod!=0) { while(mul>1) { res*=mul; mul=mul-k; } cout<<res<<endl; } else { while(mul>=k) { res*=mul; mul=mul-k; } cout<<res<<endl; } } Edited by author 05.04.2018 15:46 Edited by author 05.04.2018 15:47 #include <iostream> #include <string> using namespace std; int main() { int n,m=1; string k; cin>>n; cin>>k; int j=k.length(); for(int i=n;i>=(n%j);i-=j){ m=m*i; } cout<<m<<k; return 0; } #include <bits/stdc++.h> using namespace std; int main(){ int n, sana,s; char k[21]; cin>>n; cin.getline(k,sizeof(k)); sana = strlen(k)-1; if (1<=n&&n<=10&&1<=sana&&sana<=20){ if(n%sana==0) { s=sana;} else { s=1;} while(n>0){ s*=n; n=n-sana;} cout << s << endl; } } Edited by author 28.01.2018 23:09 |
|