Python Program for Find sum of odd factors of a number

Pavitra
Updated on 26-Sep-2019 07:32:00

489 Views

In this article, we will learn about the solution to the problem statement given below −Problem statementGiven a number input n, the task is to Find the sum of odd factors of a number.Here we first need to eliminate all the even factors.To remove all even factors, we repeatedly divide n till it is divisible by 2. After this step, we only get the odd factors of the number.Below is the implementation −Example Live Demoimport math def sumofoddFactors( n ):    #prime factors    res = 1    # ignore even factors    while n % 2 == 0:     ... Read More

How to ORDER BY DESC and display the first 3 records in MySQL?

AmitDiwan
Updated on 26-Sep-2019 07:29:43

459 Views

For this, you can use ORDER BY DESC with LIMIT. Let us first create a table −mysql> create table DemoTable (    UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    UserName varchar(100) ); Query OK, 0 rows affected (0.59 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(UserName) values('Chris'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable(UserName) values('Robert'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable(UserName) values('Bob'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable(UserName) values('David'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable(UserName) ... Read More

MySQL ORDER BY strings with underscore?

AmitDiwan
Updated on 26-Sep-2019 07:27:27

213 Views

Let us first create a table −mysql> create table DemoTable (    Name varchar(100) ); Query OK, 0 rows affected (0.60 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('John_Smith'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('Chris Brown'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('John_Doe'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values('David Miller'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values('Carol Taylor'); Query OK, 1 row affected (0.13 sec)Display all records from the table using select ... Read More

HTML onresize Event Attribute

AmitDiwan
Updated on 26-Sep-2019 07:26:46

66 Views

The HTML onresize attribute is triggered when user resize the browser window.SyntaxFollowing is the syntax −Let us see an example of HTML onresize event Attribute −Example Live Demo    body {       color: #000;       height: 100vh;       background: linear-gradient(62deg, #FBAB7E 0%, #F7CE68 100%) no-repeat;       padding: 20px;    } HTML onresize Event Attribute Demo Now resize the browser window    function resizeFn() {       document.body.style.background = 'linear-gradient(45deg, #8BC6EC 0%, #9599E2 100%) no-repeat';    } OutputNow resize the browser window to observe how onresize event attribute works.

Python Program for Find reminder of array multiplication divided by n

Pavitra
Updated on 26-Sep-2019 07:25:13

512 Views

In this article, we will learn about the solution to the problem statement given below −Problem statementGiven multiple numbers and a number input n, we need to print the remainder after multiplying all the number divisible by n.ApproachFirst, compute the remainder like arr[i] % n. Then multiply this remainder with the current result.After multiplication, again take the same remainder to avoid overflow. This is in accordance with distributive properties of modular arithmetic.( a * b) % c = ( ( a % c ) * ( b % c ) ) % cExample Live Demodef findremainder(arr, lens, n):    mul = ... Read More

Insert multiple rows from another table but the inserted records should be distinct

AmitDiwan
Updated on 26-Sep-2019 07:24:07

197 Views

For this, you can use DISTINCT along with the INSERT INTO SELECT statement. Let us first create a table −mysql> create table DemoTable1 (    Value int ); Query OK, 0 rows affected (1.03 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1 values(50); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable1 values(10); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1 values(10); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable1 values(60); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1 values(50); Query OK, 1 row ... Read More

HTML onpaste Event Attribute

AmitDiwan
Updated on 26-Sep-2019 07:22:51

141 Views

The HTML onpaste attribute is triggered when user paste some content in an HTML element in an HTML document.SyntaxFollowing is the syntax −Let us see an example of HTML onpaste event Attribute −Example Live Demo    body {       color: #000;       height: 100vh;       background: linear-gradient(62deg, #FBAB7E 0%, #F7CE68 100%) no-repeat;       text-align: center;       padding: 20px;    }    p {       border: 2px solid #fff;       padding: 8px;       text-align: justify;    }    textarea {       ... Read More

Limit the count using GROUP BY in MySQL

AmitDiwan
Updated on 26-Sep-2019 07:20:43

913 Views

Let us first create a table −mysql> create table DemoTable (    UserId int,    UserMessage varchar(100) ); Query OK, 0 rows affected (0.51 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(1, 'Hi'); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable values(2, 'Hello'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values(2, 'Good'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values(1, 'Nice'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values(1, 'Awesome'); Query OK, 1 row affected (0.16 sec) mysql> insert ... Read More

Python Program for Find minimum sum of factors of number

Pavitra
Updated on 26-Sep-2019 07:18:50

503 Views

In this article, we will learn about the solution to the problem statement given below −Problem statementGiven a number input , find the minimum sum of factors of the given number.Here we will compute all the factors and their corresponding sum and then find the minimum among them.So to find the minimum sum of the product of number, we find the sum of prime factors of the product.Here is the iterative implementation for the problem −Example Live Demo#iterative approach def findMinSum(num):    sum_ = 0    # Find factors of number and add to the sum    i = 2    while(i * i

How to get MySQL query result in same order as given by IN clause?

AmitDiwan
Updated on 26-Sep-2019 07:18:18

936 Views

For this, you can use IN() along with ORDER BY FIELD(). Let us first create a table −mysql> create table DemoTable (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    FirstName varchar(100) ); Query OK, 0 rows affected (0.64 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(FirstName) values('Chris'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable(FirstName) values('Robert'); Query OK, 1 row affected (0.08 sec) mysql> insert into DemoTable(FirstName) values('Mike'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable(FirstName) values('Sam'); Query OK, 1 row affected (0.12 sec) mysql> insert into ... Read More

Advertisements