Monday 12 June 2017

Get the modulo of a very large number that cannot be stored in any data type in C/C++!

Today we will solve problem of finding modulo of huge numbers.

Lets see the modulo operation first:

It is a distributive over addition, multiplication. i.e.

(A+B)%m = (A%m + B%m) %m
(A*B)%m = (A%m * B%m) %m

These two will help here, mainly the first one.

Consider, 'abcdepqr' is a string of digits, ok?
Is not abcdepqr = (abcde*1000 + pqr) ? Yes, it is.

Similarly, (a*10000000 + bcdepqr), right?
This is the thing we are going to apply.

What will we do is,
Get one variable to store the answer initialized to zero.

Scan the string from left to right,

Everytime multiply the answer by 10 and add the next number and take the modulo and store this as new answer.

E.g. 12345 % 100:
ans = 0
ans = (o*10 + 1)%100
ans = (1*10 + 2)%100
ans = (12*10 + 3)%100
ans = (23*10 + 4)%100
ans = (34*10 + 5)%100
ans = 45.

It means: we, at the end, are doing this only:
a*10000000 + b*1000000 + c*100000 + d*10000 + e*1000 + p*100 + q*10 + r
which is nothing but 'abcdepqr'!

This way have proved the correctness too.

Reference: https://www.hackerearth.com/practice/notes/get-the-modulo-of-a-very-large-number-that-cannot-be-stored-in-any-data-type-in-cc-1/

Monday 17 April 2017

An intelligent trader carries 3 sacks having 30 coconuts each. On the way he passes through 30 checkpoints. On every checkpoint he has to give one coconut each from each sack. How many coconuts does he have left?

Note: Initially,  it will look you quite simple and you think it is zero.
But here you have to emphasise on the word An intelligent trader, so you need to think according to an intelligent trader.
Being an intelligent trader he will definitely use all his intelligence to get the profit that is by trying to safe as much coconut as possible so
3 sacks each having 30 coconut total= 90 coconuts.
Now 30 check point and at each checkpoint he has to give coconut as much he have number of sack so, for the first 10 checkpoint he will use only one sack and give 30 coconuts.
Now he left with 2 sacks and 20 check points.
So for next 15 checkpoint he will use another sack and give coconuts from it.
After this he is left with 1 sack and 5 check points so by giving one at each point he will left with 25 coconuts.
So finally 25 coconut is left.

Saturday 12 November 2016

Active Directory

Active Directory (AD) is a directory service that Microsoft developed for Windows domain networks. A server running Active Directory Domain Services (AD DS) is called a domain controller. It authenticates and authorizes all users and computers in a Windows domain type network—assigning and enforcing security policies for all computers and installing or updating software. For example, when a user logs into a computer that is part of a Windows domain, Active Directory checks the submitted password and determines whether the user is a system administrator or normal user. Also, it allows management and storage of information at admin level and provides authentication and authorization mechanisms and a framework to deploy other related services (AD Certificate Services, AD Federated Services, etc.).

Active Directory is an integral part of the Windows 2000 architecture. Like other directory services, such as Novell Directory Services (NDS), Active Directory is a centralized and standardized system that automates network management of user data, security, and distributed resources, and enables interoperation with other directories. Active Directory is designed especially for distributed networking environments.

Active Directory provides a common interface for organizing and maintaining information related to resources connected to a variety of network directories. The directories may be systems-based (like Windows OS), application-specific or network resources, like printers. Active Directory serves as a single data store for quick data access to all users and controls access to users based on the directory's security policy.

Active Directory features include:

    • Support for the X.500 standard for global directories
    • The capability for secure extension of network operations to the Web
    • A hierarchical organization that provides a single point of access for system administration (management of user accounts, clients, servers, and applications, for example) to reduce redundancy and errors
    • An object-oriented storage organization, which allows easier access to information
    • Support for the Lightweight Directory Access Protocol (LDAP) to enable inter-directory operability

    • Designed to be both backward compatible and forward compatible.

    Active Directory (AD)

         Active Directory provides the following network services:
    • Lightweight Directory Access Protocol (LDAP) - An open standard used to access other directory services
    • Security service using the principles of Secure Sockets Layer (SSL) and Kerberos-based authentication
    • Hierarchical and internal storage of organizational data in a centralized location for faster access and better network administration
    • Data availability in multiple servers with concurrent updates to provide better scalability

    Active Directory is internally structured with a hierarchical framework. Each node in the tree-like structure is referred to as an object and associated with a network resource, such as a user or service. Like the database topic schema concept, the Active Directory schema is used to specify attribute and type for a defined Active Directory object, which facilitates searching for connected network resources based on assigned attributes. For example, if a user needs to use a printer with color printing capability, the object attribute may be set with a suitable keyword, so that it is easier to search the entire network and identify the object's location based on that keyword.
    A domain consists of objects stored in a specific security boundary and interconnected in a tree-like structure. A single domain may have multiple servers - each of which is capable of storing multiple objects. In this case, organizational data is stored in multiple locations, so a domain may have multiple sites for a single domain. Each site may have multiple domain controllers for backup and scalability reasons. Multiple domains may be connected to form a Domain Tree, which shares a common schema, configuration and global catalog (used for searching across domains). A Forest is formed by a set of multiple and trusted domain trees and forms the uppermost layer of the Active Directory.
    Novell's directory service - an Active Directory alternative - contains all server data within the directory itself, unlike Active Directory.

    References:
    https://en.wikipedia.org/wiki/Active_Directory
    https://www.techopedia.com/definition/25/active-directory
    http://serverfault.com/questions/402580/what-is-active-directory-domain-services-and-how-does-it-work

    Saturday 16 July 2016

    Two circles have their centers 21 cm apart. The radii of the circles are 10 cm and 17 cm. Find the length (in cm) of the common chord of the two circles.

     if two circles having radii a and b with the distance between them as c,
    Length of common chord= 2* Sqrt [ a^2 - ((a^2+c^2-b^2)/2c)^2]

    Ans. 84

    If the HCF of two number is 23 and the LCM is 4186, one of the two numbers is one of the following: 

    a) 276 b) 300 c) 322 d) 345. Which one is it?


    Ans. c) 322 

     Both number should be divisible by its HCF and LCM should be divisible by  both the numbers whose  HCF and LCM are to determine. 
     a) 276%23=0
          4186%276=46

    b)300%23=1
      4186%300=286

    c)322%23=0
     4186%322=0

    d)345%23=0
     4186%345=46

    How do I find two numbers when I know that their LCM is 36 and HCF is 15?


    If the HCF of the two numbers say x and y is 15; the numbers can be represented as following:
    x = 15a and y = 15b where a and b are positive integers
    It is given that LCM of x and y is 36
    Now LCM (x,y) * HCF (x,y) = x * y
    Hence, 36 * 15 = 15a * 15b
    540 = 225*a*b
    or 2.4 = a*b
    The product of two integers cannot be 2.4 hence such two numbers do not exist.

    The sum of two numbers is 52 and their LCM is 168. What are the numbers?


    As LCM of two numbers is 168 that two numbers must be factors of 168
    now think about what are all factors of 168 that are less than 52(because sum of those two is 52)
    factors=(2,3,4,6,8,7,8,12,14,24,28,42)
    from above factors u have to select two numbers such that sum of two is 52
    only possibility is 24+28