Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Bismillahir Rahman-ir Rahim
- #include <bits/stdc++.h>
- using namespace std;
- #define MAX 32000
- #define PI acos(-1)
- #define debug(x) cout << '>' << #x << " : " << x << endl;
- #define all(c) c.begin(), c.end()
- //#define m (pow(10, 9)+7)
- typedef unsigned long long ull;
- typedef long long ll;
- string strsum(string a, string b){
- int len = max(a.size(), b.size());
- reverse(a.begin(), a.end());
- reverse(b.begin(), b.end());
- int ans, carry = 0;
- string sum;
- for(int i = 0; i < len; i++){
- ans = carry;
- if(a.size() > i){
- ans += a[i] - '0';
- }
- if(b.size() > i){
- ans += b[i] - '0';
- }
- if(ans > 9){
- carry = ans / 10;
- ans = ans % 10;
- }
- else{
- carry = 0;
- }
- sum += (char)(ans + (int)'0');
- }
- if(carry){
- sum += (char)(carry + (int)'0');
- }
- reverse(sum.begin(), sum.end());
- return sum;
- }
- string str_multiplic(string a, string b)
- {
- int maxlen = max(a.size(), b.size()), minlen = min(a.size(), b.size()), temp;
- string ans ="0", str, mainans = "0";
- stringstream ss;
- if(a.size() < b.size()){
- swap(a, b);
- }
- reverse(a.begin(), a.end());
- reverse(b.begin(), b.end());
- for(int i = 0; i < minlen; i++){
- ans = "0";
- for(int j = 0; j < maxlen; j++){
- temp = (b[i] - '0')*(a[j] - '0');
- //cout <<"temp: " <<temp << endl;
- stringstream ss;
- ss << temp;
- ss >> str;
- for(int k = 0; k < j; k++){
- str+="0";
- }
- //cout <<"str: " << str << endl;
- ans = strsum(ans, str);
- //cout << "ans: " << ans << endl;
- }
- for(int l = 0; l < i; l++){
- ans += "0";
- }
- mainans = strsum(mainans, ans);
- //cout <<"mainans: " <<mainans << endl;
- }
- return mainans;
- }
- vector < string > vec;
- void dp_mult()
- {
- //str = "0";
- vec.push_back("1");
- string ans = "1";
- int i = 1, limit = 400;
- while(1) {
- string str;
- stringstream ss;
- ss << i;
- ss >> str;
- ans = str_multiplic(ans, str);
- vec.push_back(ans);
- if(i == limit) break;
- i++;
- }
- }
- int main()
- {
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- dp_mult();
- int n;
- while(cin >> n) {
- cout << n << "!" << endl;
- cout << vec[n] << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement