শুক্রবার, ৪ নভেম্বর, ২০১৬

Find the minimum number of length n, such that it is simultaneously divisible by some numbers(2,3,5,7)

#include < bits / stdc++.h>
#include <iostream>
using namespace std;
main()
{
    long long n;
    while(cin>>n)
    {
        if(n==1||n==2)
            cout<<"-1"<<endl;
        else
        {
            if(n==3)
            {
                cout<<210<<endl;
            }
            else
            {
                string s;
                long long i,k,k1=0,l,k2,k3;
                s='1';
                for(i=0;i<n-1;i++)
                    {
                        s+='0';
                    }
                    l=s.size();
                for(i=0;i<l;i++)
                {
                    k=k1*10+(s[i]-48);
                    k1=k%210;
                }
                k2=210-k1;
                k3=l-1;
                char ch;
                while(k2!=0)
                {
                    ch=k2%10;
                    s[k3]=ch+48;
                    k2/=10;
                    k3--;
                }
                cout<<s<<endl;
            }
        }
    }

কোন মন্তব্য নেই:

একটি মন্তব্য পোস্ট করুন

Factory Pattern

Factory Method  is a creational design pattern that provides an interface for creating objects in a superclass but allows subclasses to alte...