Soluții

Python Script for Number of solutions to Modular Equations

Given A and B, the task is to find the number of possible values that X can take such that the given modular equation (A mod X) = B holds good. Here, X is also called a solution of the modular equation.

Examples:

Input : A = 26, B = 2
Output : 6
Explanation
X can be equal to any of {3, 4, 6, 8,
12, 24} as A modulus any of these values
equals 2 i. e., (26 mod 3) = (26 mod 4) 
= (26 mod 6) = (26 mod 8) =Output:2 

Input : 21 5
Output : 2
Explanation
X can be equal to any of {8, 16} as A modulus 
any of these values equals 5 i.e. (21 mod 
8) = (21 mod 16) = 5
[mai mult...]

Python Script for Legendre’s Conjecture

Conjecture: A conjecture is a proposition or conclusion based upon incompleate information to which no proof has been found i.e it has not been proved or disproved.

Mathematically,
there is always one prime p in the range n^2 to (n + 1)^2 where n is any natural number.

for examples:
2 and 3 are the primes in the range 1^2 to 2^2.

5 and 7 are the primes in the range 2^2 to 3^2.

11 and 13 are the primes in the range 3^2 to 4^2.

17 and 19 are the primes in the range 4^2 to 5^2.

[mai mult...]

How to manage Search Indexing

You have three options when it comes to Windows Search Indexing:

  1. Remove folders from indexation to reduce the scan time
  2. Disable content indexation
  3. Disable Windows Search indexing completely
  • Remove folders from indexation

It may be enough sometimes to limit the folders that you want Windows Search to index. Windows Search indexes some folders, like Downloads, Documents or Desktop by default. If you are a heavy downloader, the downloads folder may be full of files and folders all the time. Additionally, file and folders may get deleted regularly as well which means that indexing has a lot of work to do to process that folder.

Tip: It is a good idea to limit indexation to folders that you want Windows Search to index. If you work with a lot of documents and use Windows Search to find them, you may want to keep the Documents folder but remove others that you don’t require.

  • Indexing Options

You manage the indexing locations in the Indexing Options. To load the configuration, tap on the Windows-key, type indexing options, and select the result of the same name.

The Indexing Options window lists all folders that are included or excluded from indexation. It furthermore highlights the number of items that are in the index currently, and the status of indexing.

Select Modify at the bottom to manage the indexing locations. This opens a dual-pane window that lists all available locations in the top pane, and all folders selected for indexation at the bottom.

Tip: Make sure you click on the “show all locations” button to reveal locations that may not be shown by default.

You add new locations by checking boxes in front of items in the top pane, and remove existing ones by removing the checkmarks from the boxes. Since you may not want to navigate the top folder structure to locate all indexed locations, you may click on a location in the lower pane to jump straight to it. This allows you to remove it with just two clicks.

When you remove a location from Windows Search indexing, Windows Search won’t scan it anymore when it runs scans for changes in those locations.

You may also exclude subfolders from indexation. This is useful if you want some locations of a folder to be indexed but not others. Using exclude options may further help reduce the load of indexation when Windows Search indexing runs.

Check the Advanced options once you are done. Make sure that the options “index encrypted files” and “treat similar words with diacritics as different words” are not selected.

You may delete and recreate the index on the page as well, and change the location of the index. The latter may be useful if the computer’s main drive is slower than another drive connected to the device.

  • Disable content indexation

Another thing that you may want to check is whether Windows Search is allowed to index file content and not only file properties on select drives. It takes more time obviously to scan the content of files as well, and if you don’t need that, you may want to make sure that this is not done on the Windows machine in question.

You need to repeat the following steps for any drive of the Windows 10 PC:

  1. Open File Explorer.
  2. Right-click on the drive, e.g. Local Disk (c:), and select properties from the context menu.
  3. Go to the General tab if it does not open automatically.
  4. Remove the checkmark from “Allow files on this drive to have contents indexed in addition to file properties”.
  5. Confirm the Attribute changes by selecting “apply changes to drive, subfolders and files, and click ok.

The process may take a while before it completes. It can run for minutes and even longer than that depending on the size of the drive. You may get an access denied error. I suggest you select “ignore all” when that happens to tell Windows that it should ignore any future access denied error automatically.

  • Disable Windows Search Indexing completely

The final option that you have is to disable Windows Search indexing completely. This prevents any indexation processes and should improve the situation on all devices that are affected by high load or performance issues that are caused by Windows Search indexing.

  1. Tap on the Windows-key, type services.msc, and tap on the Enter-key. This opens the Windows Services Manager.
  2. Locate Windows Search when the services listing opens. The services are sorted automatically, so jump to the bottom to find it more quickly.
  3. Right-click on Windows Search and select properties from the menu.
  4. Switch the startup type to “disabled”.
  5. Select “stop” under service status to block the service from running in that session.
  6. Click apply and then ok.

You may still run searches, but without indexing. This means that searches may take longer to complete.

[mai mult...]

Find Out List of All Open Ports in Linux

In computer networking, and more definitely in software terms, a port is a logical entity which acts as a endpoint of communication to identify a given application or process on an Linux operating system. It is a 16-bit number (0 to 65535) which differentiates one application from another on end systems.

The two most popular Internet transport protocols, Transmission Control Protocol (TCP) and the User Datagram Protocol (UDP) and other less known protocols use port numbers for communication sessions (source and destination port numbers in conjunction with the source and destination IP addresses).

In addition, a combination of an IP address, port and protocol such as TCP/UDP is known as a socket, and every service must have a unique socket.

Below are the different categories of ports:

  1. 0-1023 – the Well Known Ports, also referred to as System Ports.
  2. 1024-49151 – the Registered Ports, also known as User Ports.
  3. 49152-65535 – the Dynamic Ports, also referred to as the Private Ports.

You can view a list of different applications and port/protocol combination in /etc/services file in Linux using cat command:

$ cat /etc/services 
OR
$ cat /etc/services | less
Network Services and Ports
# /etc/services:
# $Id: services,v 1.48 2009/11/11 14:32:31 ovasik Exp $
#
# Network services, Internet style
# IANA services version: last updated 2009-11-10
#
# Note that it is presently the policy of IANA to assign a single well-known
# port number for both TCP and UDP; hence, most entries here have two entries
# even if the protocol doesn't support UDP operations.
# Updated from RFC 1700, ``Assigned Numbers'' (October 1994).  Not all ports
# are included, only the more common ones.
#
# The latest IANA port assignments can be gotten from
#       http://www.iana.org/assignments/port-numbers
# The Well Known Ports are those from 0 through 1023.
# The Registered Ports are those from 1024 through 49151
# The Dynamic and/or Private Ports are those from 49152 through 65535
#
# Each line describes one service, and is of the form:
#
# service-name  port/protocol  [aliases ...]   [# comment]

tcpmux          1/tcp                           # TCP port service multiplexer
tcpmux          1/udp                           # TCP port service multiplexer
rje             5/tcp                           # Remote Job Entry
rje             5/udp                           # Remote Job Entry
echo            7/tcp
echo            7/udp
discard         9/tcp           sink null
discard         9/udp           sink null
systat          11/tcp          users
systat          11/udp          users
daytime         13/tcp
daytime         13/udp
qotd            17/tcp          quote
qotd            17/udp          quote
msp             18/tcp                          # message send protocol
msp             18/udp                          # message send protocol
chargen         19/tcp          ttytst source
chargen         19/udp          ttytst source
ftp-data        20/tcp
ftp-data        20/udp
# 21 is registered to ftp, but also used by fsp
ftp             21/tcp
ftp             21/udp          fsp fspd
ssh             22/tcp                          # The Secure Shell (SSH) Protocol
ssh             22/udp                          # The Secure Shell (SSH) Protocol
telnet          23/tcp
telnet          23/udp

To list all open ports or currently running ports including TCP and UDP in Linux, we will use netstat, is a powerful tool for monitoring network connections and statistics.

List All Network Ports Using Netstat Command
$ netstat -lntu

Proto Recv-Q Send-Q Local Address               Foreign Address             State      
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      
tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      
tcp        0      0 0.0.0.0:25                  0.0.0.0:*                   LISTEN      
tcp        0      0 :::22                       :::*                        LISTEN      
tcp        0      0 :::80                       :::*                        LISTEN      
tcp        0      0 :::25                       :::*                        LISTEN      
udp        0      0 0.0.0.0:68                  0.0.0.0:*                               

Where,

  1. -l – prints only listening sockets
  2. -n – shows port number
  3. -t – enables listing of tcp ports
  4. -u – enables listing of udp ports

You can also use ss command, a well known useful utility for examining sockets in a Linux system. Run the command below to list all your open TCP and UCP ports:

List All Network Ports Using ss Command
$ ss -lntu

Netid State      Recv-Q Send-Q               Local Address:Port       Peer Address:Port 
udp   UNCONN     0      0                    *:68                     *:*     
tcp   LISTEN     0      128                  :::22                    :::*     
tcp   LISTEN     0      128                  *:22                     *:*     
tcp   LISTEN     0      50                   *:3306                   *:*     
tcp   LISTEN     0      128                  :::80                    ::*     
tcp   LISTEN     0      100                  :::25                    :::*     
tcp   LISTEN     0      100                  *:25  
[mai mult...]