ENG  RUS Timus Online Judge
Online Judge
Problems
Authors
Online contests
Site news
Webboard
Problem set
Submit solution
Judge status
Guide
Register
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

## Discussion of Problem 1083. Factorials!!!

C++ AC
Posted by D4nick 3 Jan 2019 06:03
#include <iostream>
#include <string>
using namespace std;
long long fact(int n, int k) {
long long fact = 0, ans = 1; int i = 0;
for (; n - i*k > 0; i++) {
ans *= n - i*k;
}
return ans;
}
int main() {
int n, k; string s;
cin >> n >> s;
k = s.length();
cout << fact(n, k);
}

Edited by author 30.01.2019 03:24
Re: C++ AC
Posted by abid1729 9 Aug 2019 22:57
#include<bits/stdc++.h>
#include<cstring>
#include<cmath>
using namespace std;
int fact(int h){
int p=1,i=1;
while(h--){
p*=i;
i++;
}
return p;
}
long power(int a, int b){
int c;
while(b--){
c*=a;
}
return c;
}
int main()
{
int n,i,j=1;
string a;
cin>>n>>a;
int k=a.length();
i=n/k;
if(n%k==0){
cout<<power(k,i)*fact(i);
}
else{
for(i=(n%k);i<=n;i+=k){
j*=i;
}
cout<<j;
}
}
Re: C++ AC
Posted by Asad Binsaber 7 Nov 2019 11:54
#include<bits/stdc++.h>

using namespace std;
int main()
{
int n, k, i, t=1;
string str;

cin>>n>>str;

k=str.length();

for(i=n; i>=0; ){
if(i==0) break;
else t = t * i;
if(i==(n%k)) break;
if(i<k) i=n%k;
else i=i-k;
}
cout<<t<<endl;

return 0;
}