1597003200

# Sum of elements of a Geometric Progression (GP) in a given range

Given a Geometric Progression series in arr[] and Q queries in the form of [L, R], where L is the left boundary of the range and R is the right boundary. The task is to find the sum of the Geometric Progression elements in the given range.

Note: The range is 1-indexed and** 1 ≤ L, R ≤ N**, where N is the size of arr.

Examples:

Input:_ arr[] = {2, 4, 8, 16, 32, 64, 128, 256}, Q = [[2, 4], [2, 6], [5, 8]] _

Output:

_28 _

_124 _

480

Explanation:

_Range 1: arr = {4, 8, 16}. Therefore sum = 28 _

_Range 2: arr = {4, 8, 16, 32, 64}. Therefore sum = 124 _

Range 3: arr = {32, 64, 128, 256}. Therefore sum = 480

Input:_ arr[] = {7, 7, 7, 7, 7, 7}, Q = [[1, 6], [2, 4], [3, 3]] _

Output:

42

_21 _

_7 _

Explanation:

Range 1: arr = {7, 7, 7, 7, 7, 7}. Therefore sum = 42

_Range 2: arr = {7, 7, 7}. Therefore sum = 21 _

Range 3: arr = {7}. Therefore sum = 7

Approach: Since the given sequence is an Geometric progression, the sum can be easily found out in two steps efficiently:

1. Get the first element of the range.
2. If **d = 1, **then multiply **d*k **to it, else multiply the (dk – 1)/(d – 1) to it, where d is the common ratio of the GP and k is number of elements in the range.

For example:

Suppose a[i] be the first element of the range, d be the common ratio of GP and k be the number of elements in the given range.

Then the sum of the range would be

_= a[i] + a[i+1] + a[i+2] + …… + a[i+k-1] _

_= a[i] + (a[i] * d) + (a[i] * d * d) + …. + (a[i] * dk) _

_= a[i] * (1 + d + … + dk) _

= a[i] * (dk – 1)/(d – 1)

Below is the implementation of the above approach:

### Python3

`## Python program to`

`## find the sum of elements`

`## of an GP in the given range`

`## Function to find sum in the given range`

`**def**` `findSum(arr, n, left, right):`

`## Find the value of k`

`k` `**=**` `right` `**-**` `left` `**+**` `1`

`## Find the common difference`

`d` `**=**` `arr[``1``]` `**//**` `arr[``0``]`

`## Find the sum`

`ans` `**=**` `arr[left` `**-**` `1``]`

`**if**` `d` `**==**` `1``:`

`ans` `**=**` `ans` `*****` `d` `*****` `k`

`**else**``:`

`ans` `**=**` `ans` `*****` `(d` `******` `k` `**-**` `1``)` `**//**` `(d` `**-**``1``)`

`**return**` `ans`

`## Driver code`

`**if**` `__name__` `**==**` `'__main__'``:`

`arr` `**=**` `[` `2``,` `4``,` `8``,` `16``,` `32``,` `64``,` `128``,` `256` `]`

`queries` `**=**` `3`

`q` `**=**` `[[` `2``,` `4` `], [` `2``,` `6` `], [` `5``,` `8` `]]`

`n` `**=**` `len``(arr)`

`**for**` `i` `**in**` `range``(queries):`

`**print**``(findSum(arr, n, q[i][``0``], q[i][``1``]))`

Output:

``````28
124
480
``````
• Time complexity:_ O(Q) _
• Space complexity:_ O(1)_

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

#arrays #mathematical #geometric progression #css #python

1674813120

## Validate Multi Step Form Using jQuery

In this article, we will see how to validate multi step form wizard using jquery. Here, we will learn to validate the multi step form using jquery. First, we create the multi step form using bootstrap. Also, in this example, we are not using any jquery plugin for multi step form wizard.

So, let's see jquery multi step form with validation, how to create multi step form, multi step form wizard with jquery validation, bootstrap 4 multi step form wizard with validation, multi step form bootstrap 5, and jQuery multi step form with validation and next previous navigation.

``````<html lang="en">
<body>
<div class="main">
<h3>How To Validate Multi Step Form Using jQuery - Websolutionstuff</h3>
<form id="multistep_form">
<!-- progressbar -->
<li class="active"></li>
<li></li>
<li></li>
</ul>
<!-- Step 01 -->
<div class="multistep-box">
<div class="title-box">
</div>
<p>
<input type="text" name="email" placeholder="Email" id="email">
<span id="error-email"></span>
</p>
<p>
<span id="error-pass"></span>
</p>
<p>
<span id="error-cpass"></span>
</p>
<p class="nxt-prev-button"><input type="button" name="next" class="fs_next_btn action-button" value="Next" /></p>
</div>
<!-- Step 02 -->
<div class="multistep-box">
<div class="title-box">
<h2>Social Profiles</h2>
</div>
<p>
</p>
<p>
</p>
<p>
</p>
<p class="nxt-prev-button">
<input type="button" name="previous" class="previous action-button" value="Previous" />
<input type="button" name="next" class="ss_next_btn action-button" value="Next" />
</p>
</div>
<!-- Step 03 -->
<div class="multistep-box">
<div class="title-box">
<h2>Personal Details</h2>
</div>
<p>
<input type="text" name="fname" placeholder="First Name" id="fname">
<span id="error-fname"></span>
</p>
<p>
<input type="text" name="lname" placeholder="Last Name" id="lname">
<span id="error-lname"></span>
</p>
<p>
<input type="text" name="phone" placeholder="Phone" id="phone">
<span id="error-phone"></span>
</p>
<p>
</p>
<p class="nxt-prev-button"><input type="button" name="previous" class="previous action-button" value="Previous" />
<input type="submit" name="submit" class="submit_btn ts_next_btn action-button" value="Submit" />
</p>
</div>
</form>
<h1>You are successfully logged in</h1>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-easing/1.4.0/jquery.easing.js" type="text/javascript"></script>
</body>
</html>``````

``````body {
display: inline-block;
width: 100%;
height: 100vh;
overflow: hidden;
background-repeat: no-repeat;
background-size: cover;
position: relative;
margin: 0;
font-weight: 400;
font-family: 'Roboto', sans-serif;
}
body:before {
content: "";
display: block;
width: 100%;
height: 100%;
background: rgba(0,0,0,0.5);
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
}
.main {
position: absolute;
left: 0;
right: 0;
top: 30px;
margin: 0 auto;
height: 515px;
}
input:-internal-autofill-selected {
background-color: #fff !important;
}
#multistep_form {
width: 550px;
margin: 0 auto;
text-align: center;
position: relative;
height: 100%;
z-index: 999;
opacity: 1;
visibility: visible;
}
overflow: hidden;
margin: 0 auto 30px;
}
list-style-type: none;
width: 33.33%;
float: left;
position: relative;
font-size: 16px;
font-weight: bold;
font-family: monospace;
color: #fff;
text-transform: uppercase;
}
width: 35px;
line-height: 35px;
display: block;
font-size: 22px;
color: #888;
font-family: monospace;
background-color: #fff;
margin: 0 auto;
background-repeat: no-repeat;
font-family: 'Roboto', sans-serif;
}
content: "1";
}
content: "2";
}
content: "3";
}
content: '';
width: 100%;
height: 5px;
background: #fff;
position: absolute;
left: -50%;
top: 50%;
z-index: -1;
}
content: none;
}
background-image: linear-gradient(to right top, #35e8c3, #36edbb, #3df2b2, #4af7a7, #59fb9b) !important;
color: #fff !important;
transition: all 0.5s;
}
/*title*/
.title-box {
width: 100%;
margin: 0 0 30px 0;
}
.title-box h2 {
font-size: 22px;
text-transform: uppercase;
color: #2C3E50;
margin: 0;
font-family: cursive;
display: inline-block;
position: relative;
font-family: 'Roboto', sans-serif;
}
.title-box h2:before {
content: "";
background: #6ddc8b;
width: 70px;
height: 2px;
position: absolute;
bottom: 0;
left: 0;
right: 0;
margin: 0 auto;
display: block;
}
.title-box h2:after {
content: "";
background: #6ddc8b;
width: 50px;
height: 2px;
position: absolute;
bottom: -5px;
left: 0;
right: 0;
margin: 0 auto;
display: block;
}
/*Input and Button*/
.multistep-box {
background: white;
border: 0 none;
box-shadow: 1px 1px 55px 3px rgba(255, 255, 255, 0.4);
box-sizing: border-box;
width: 80%;
margin: 0 10%;
position: absolute;
}
.multistep-box:not(:first-of-type) {
display: none;
}
.multistep-box p {
margin: 0 0 12px 0;
text-align: left;
}
.multistep-box span {
font-size: 12px;
color: #FF0000;
}
input, textarea {
border: 1px solid #ccc;
margin: 0;
width: 100%;
box-sizing: border-box;
font-family: 'Roboto', sans-serif;
color: #2C3E50;
font-size: 13px;
transition: all 0.5s;
outline: none;
}
input:focus, textarea:focus {
box-shadow: inset 0px 0px 50px 2px rgb(0,0,0,0.1);
}
input.box_error, textarea.box_error {
border-color: #FF0000;
box-shadow: inset 0px 0px 50px 2px rgb(255,0,0,0.1);
}
input.box_error:focus, textarea.box_error:focus {
box-shadow: inset 0px 0px 50px 2px rgb(255,0,0,0.1);
}
p.nxt-prev-button {
margin: 25px 0 0 0;
text-align: center;
}
.action-button {
width: 100px;
font-weight: bold;
color: white;
border: 0 none;
cursor: pointer;
margin: 0 5px;
background-image: linear-gradient(to right top, #35e8c3, #36edbb, #3df2b2, #4af7a7, #59fb9b);
transition: all 0.5s;
}
.action-button:hover,
.action-button:focus {
box-shadow: 0 0 0 2px white, 0 0 0 3px #6ce199;
}
.form_submited #multistep_form {
opacity: 0;
visibility: hidden;
}
.form_submited h1 {
-webkit-background-clip: text;
transform: translate(0%, 0%);
-webkit-transform: translate(0%, 0%);
transition: all 0.3s ease;
opacity: 1;
visibility: visible;
}
h1 {
margin: 0;
text-align: center;
font-size: 90px;
background-image: linear-gradient(to right top, #35e8c3, #36edbb, #3df2b2, #4af7a7, #59fb9b) !important;
background-image: linear-gradient(to right top, #35e8c3, #36edbb, #3df2b2, #4af7a7, #59fb9b) !important;
color: transparent;
-webkit-background-clip: text;
-webkit-background-clip: text;
transform: translate(0%, -80%);
-webkit-transform: translate(0%, -80%);
transition: all 0.3s ease;
opacity: 0;
visibility: hidden;
position: absolute;
left: 0;
right: 0;
margin: 0 auto;
text-align: center;
top: 50%;
}
h3{
color:#fff;
text-align:center;
margin-bottom:20px;
}``````

``````var current_slide, next_slide, previous_slide;
var left, opacity, scale;
var animation;

var error = false;

// email validation
\$("#email").keyup(function() {
var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?\$/;
if (!emailReg.test(\$("#email").val())) {
error = true;
} else {
\$("#error-email").text('');
error = false;
\$("#email").removeClass("box_error");
}
});
\$("#pass").keyup(function() {
var pass = \$("#pass").val();
var cpass = \$("#cpass").val();

if (pass != '') {
\$("#error-pass").text('');
error = false;
\$("#pass").removeClass("box_error");
}
if (pass != cpass && cpass != '') {
error = true;
} else {
\$("#error-cpass").text('');
error = false;
}
});
\$("#cpass").keyup(function() {
var pass = \$("#pass").val();
var cpass = \$("#cpass").val();

if (pass != cpass) {
error = true;
} else {
\$("#error-cpass").text('');
error = false;
\$("#cpass").removeClass("box_error");
}
});
error = true;
} else {
error = false;
}
});
error = true;
} else {
error = false;
}
});
error = true;
} else {
error = false;
}
});
// first name
\$("#fname").keyup(function() {
var fname = \$("#fname").val();
if (fname == '') {
error = true;
} else {
\$("#error-fname").text('');
error = false;
}
if ((fname.length <= 2) || (fname.length > 20)) {
\$("#error-fname").text("User length must be between 2 and 20 Characters.");
error = true;
}
if (!isNaN(fname)) {
\$("#error-fname").text("Only Characters are allowed.");
error = true;
} else {
\$("#fname").removeClass("box_error");
}
});
// last name
\$("#lname").keyup(function() {
var lname = \$("#lname").val();
if (lname != lname) {
error = true;
} else {
\$("#error-lname").text('');
error = false;
}
if ((lname.length <= 2) || (lname.length > 20)) {
\$("#error-lname").text("User length must be between 2 and 20 Characters.");
error = true;
}
if (!isNaN(lname)) {
\$("#error-lname").text("Only Characters are allowed.");
error = true;
} else {
\$("#lname").removeClass("box_error");
}
});
// phone
\$("#phone").keyup(function() {
var phone = \$("#phone").val();
if (phone != phone) {
error = true;
} else {
\$("#error-phone").text('');
error = false;
}
if (phone.length != 10) {
\$("#error-phone").text("Mobile number must be of 10 Digits only.");
error = true;
} else {
\$("#phone").removeClass("box_error");
}
});
error = true;
} else {
error = false;
}
});

// first step validation
\$(".fs_next_btn").click(function() {
// email
if (\$("#email").val() == '') {
error = true;
} else {
var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?\$/;
if (!emailReg.test(\$("#email").val())) {
error = true;
} else {
\$("#error-email").text('');
\$("#email").removeClass("box_error");
}
}
if (\$("#pass").val() == '') {
error = true;
}
if (\$("#cpass").val() == '') {
error = true;
} else {
var pass = \$("#pass").val();
var cpass = \$("#cpass").val();

if (pass != cpass) {
error = true;
} else {
\$("#error-cpass").text('');
\$("#pass").removeClass("box_error");
\$("#cpass").removeClass("box_error");
}
}
// animation
if (!error) {
if (animation) return false;
animation = true;

current_slide = \$(this).parent().parent();
next_slide = \$(this).parent().parent().next();

next_slide.show();
current_slide.animate({
opacity: 0
}, {
step: function(now, mx) {
scale = 1 - (1 - now) * 0.2;
left = (now * 50) + "%";
opacity = 1 - now;
current_slide.css({
'transform': 'scale(' + scale + ')'
});
next_slide.css({
'left': left,
'opacity': opacity
});
},
duration: 800,
complete: function() {
current_slide.hide();
animation = false;
},
easing: 'easeInOutBack'
});
}
});
// second step validation
\$(".ss_next_btn").click(function() {
error = true;
} else {
error = true;
} else {
}
}
error = true;
} else {
error = true;
} else {
}
}
error = true;
} else {
error = true;
} else {
}
}

if (!error) {
if (animation) return false;
animation = true;

current_slide = \$(this).parent().parent();
next_slide = \$(this).parent().parent().next();

next_slide.show();
current_slide.animate({
opacity: 0
}, {
step: function(now, mx) {
scale = 1 - (1 - now) * 0.2;
left = (now * 50) + "%";
opacity = 1 - now;
current_slide.css({
'transform': 'scale(' + scale + ')'
});
next_slide.css({
'left': left,
'opacity': opacity
});
},
duration: 800,
complete: function() {
current_slide.hide();
animation = false;
},
easing: 'easeInOutBack'
});
}

});

// third step validation
\$(".ts_next_btn").click(function() {
// first name
if (\$("#fname").val() == '') {
error = true;
} else {
var fname = \$("#fname").val();
if (fname != fname) {
\$("#error-fname").text('First name is required.');
error = true;
} else {
\$("#error-fname").text('');
error = false;
\$("#fname").removeClass("box_error");
}
if ((fname.length <= 2) || (fname.length > 20)) {
\$("#error-fname").text("User length must be between 2 and 20 Characters.");
error = true;
}
if (!isNaN(fname)) {
\$("#error-fname").text("Only Characters are allowed.");
error = true;
} else {
\$("#fname").removeClass("box_error");
}
}
// last name
if (\$("#lname").val() == '') {
error = true;
} else {
var lname = \$("#lname").val();
if (lname != lname) {
\$("#error-lname").text('Last name is required.');
error = true;
} else {
\$("#error-lname").text('');
error = false;
}
if ((lname.length <= 2) || (lname.length > 20)) {
\$("#error-lname").text("User length must be between 2 and 20 Characters.");
error = true;
}
if (!isNaN(lname)) {
\$("#error-lname").text("Only Characters are allowed.");
error = true;
} else {
\$("#lname").removeClass("box_error");
}
}
// phone
if (\$("#phone").val() == '') {
error = true;
} else {
var phone = \$("#phone").val();
if (phone != phone) {
\$("#error-phone").text('Phone number is required.');
error = true;
} else {
\$("#error-phone").text('');
error = false;
}
if (phone.length != 10) {
\$("#error-phone").text("Mobile number must be of 10 Digits only.");
error = true;
} else {
\$("#phone").removeClass("box_error");
}
}
error = true;
} else {
error = true;
} else {
error = false;
}
}

if (!error) {
if (animation) return false;
animation = true;

current_slide = \$(this).parent().parent();
next_slide = \$(this).parent().parent().next();

next_slide.show();
current_slide.animate({
opacity: 0
}, {
step: function(now, mx) {
scale = 1 - (1 - now) * 0.2;
left = (now * 50) + "%";
opacity = 1 - now;
current_slide.css({
'transform': 'scale(' + scale + ')'
});
next_slide.css({
'left': left,
'opacity': opacity
});
},
duration: 800,
complete: function() {
current_slide.hide();
animation = false;
},
easing: 'easeInOutBack'
});
}
});
// previous
\$(".previous").click(function() {
if (animation) return false;
animation = true;

current_slide = \$(this).parent().parent();
previous_slide = \$(this).parent().parent().prev();

previous_slide.show();
current_slide.animate({
opacity: 0
}, {
step: function(now, mx) {
scale = 0.8 + (1 - now) * 0.2;
left = ((1 - now) * 50) + "%";
opacity = 1 - now;
current_slide.css({
'left': left
});
previous_slide.css({
'transform': 'scale(' + scale + ')',
'opacity': opacity
});
},
duration: 800,
complete: function() {
current_slide.hide();
animation = false;
},
easing: 'easeInOutBack'
});
});

\$(".submit_btn").click(function() {
if (!error){
}
return false;
})``````

Output:

Original article source at: https://websolutionstuff.com/

1597003200

## Sum of elements of a Geometric Progression (GP) in a given range

Given a Geometric Progression series in arr[] and Q queries in the form of [L, R], where L is the left boundary of the range and R is the right boundary. The task is to find the sum of the Geometric Progression elements in the given range.

Note: The range is 1-indexed and** 1 ≤ L, R ≤ N**, where N is the size of arr.

Examples:

Input:_ arr[] = {2, 4, 8, 16, 32, 64, 128, 256}, Q = [[2, 4], [2, 6], [5, 8]] _

Output:

_28 _

_124 _

480

Explanation:

_Range 1: arr = {4, 8, 16}. Therefore sum = 28 _

_Range 2: arr = {4, 8, 16, 32, 64}. Therefore sum = 124 _

Range 3: arr = {32, 64, 128, 256}. Therefore sum = 480

Input:_ arr[] = {7, 7, 7, 7, 7, 7}, Q = [[1, 6], [2, 4], [3, 3]] _

Output:

42

_21 _

_7 _

Explanation:

Range 1: arr = {7, 7, 7, 7, 7, 7}. Therefore sum = 42

_Range 2: arr = {7, 7, 7}. Therefore sum = 21 _

Range 3: arr = {7}. Therefore sum = 7

Approach: Since the given sequence is an Geometric progression, the sum can be easily found out in two steps efficiently:

1. Get the first element of the range.
2. If **d = 1, **then multiply **d*k **to it, else multiply the (dk – 1)/(d – 1) to it, where d is the common ratio of the GP and k is number of elements in the range.

For example:

Suppose a[i] be the first element of the range, d be the common ratio of GP and k be the number of elements in the given range.

Then the sum of the range would be

_= a[i] + a[i+1] + a[i+2] + …… + a[i+k-1] _

_= a[i] + (a[i] * d) + (a[i] * d * d) + …. + (a[i] * dk) _

_= a[i] * (1 + d + … + dk) _

= a[i] * (dk – 1)/(d – 1)

Below is the implementation of the above approach:

### Python3

`## Python program to`

`## find the sum of elements`

`## of an GP in the given range`

`## Function to find sum in the given range`

`**def**` `findSum(arr, n, left, right):`

`## Find the value of k`

`k` `**=**` `right` `**-**` `left` `**+**` `1`

`## Find the common difference`

`d` `**=**` `arr[``1``]` `**//**` `arr[``0``]`

`## Find the sum`

`ans` `**=**` `arr[left` `**-**` `1``]`

`**if**` `d` `**==**` `1``:`

`ans` `**=**` `ans` `*****` `d` `*****` `k`

`**else**``:`

`ans` `**=**` `ans` `*****` `(d` `******` `k` `**-**` `1``)` `**//**` `(d` `**-**``1``)`

`**return**` `ans`

`## Driver code`

`**if**` `__name__` `**==**` `'__main__'``:`

`arr` `**=**` `[` `2``,` `4``,` `8``,` `16``,` `32``,` `64``,` `128``,` `256` `]`

`queries` `**=**` `3`

`q` `**=**` `[[` `2``,` `4` `], [` `2``,` `6` `], [` `5``,` `8` `]]`

`n` `**=**` `len``(arr)`

`**for**` `i` `**in**` `range``(queries):`

`**print**``(findSum(arr, n, q[i][``0``], q[i][``1``]))`

Output:

``````28
124
480
``````
• Time complexity:_ O(Q) _
• Space complexity:_ O(1)_

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

#arrays #mathematical #geometric progression #css #python

1655889360

## Element iOS

Element iOS is an iOS Matrix client provided by Element. It is based on MatrixSDK.

## Beta testing

You can try last beta build by accessing our TestFlight Public Link. For questions and feedback about latest TestFlight build, please access the Element iOS Matrix room: #element-ios:matrix.org.

## Build instructions

If you have already everything installed, opening the project workspace in Xcode should be as easy as:

``````\$ xcodegen                  # Create the xcodeproj with all project source files
\$ pod install               # Create the xcworkspace with all project dependencies
\$ open Riot.xcworkspace     # Open Xcode
``````

Else, you can visit our installation guide. This guide also offers more details and advanced usage like using MatrixSDK in its development version.

## Contributing

If you want to contribute to Element iOS code or translations, go to the contribution guide.

## Support

When you are experiencing an issue on Element iOS, please first search in GitHub issues and then in #element-ios:matrix.org. If after your research you still have a question, ask at #element-ios:matrix.org. Otherwise feel free to create a GitHub issue if you encounter a bug or a crash, by explaining clearly in detail what happened. You can also perform bug reporting (Rageshake) from the Element application by shaking your phone or going to the application settings. This is especially recommended when you encounter a crash.

Author: vector-im
Source Code: https://github.com/vector-im/element-ios

#swift #ios #mobileapp

1621172164

## Circular Progress Bar Using Html CSS and Bootstrap

How to create an animated circular progress bar using only HTML CSS and BoostApp programming code. I have designed many more types of animated progress bars before but this design has been designed in a completely modern way.

Animated circular Progress Bar is a type of statistical design used in a variety of websites. It is mainly used to indicate the percentage of one’s qualification in a portfolio website or personal website. It is fully animated, that is, under normal conditions, it has zero percent then it will gradually reach the pre-determined percentage. Different colors have been used to denote percentages.

Demo

#circular progress bar #progress bar #animated circular progress bar #skill #progress

1625717787

## Reach out to more customers: get a progressive web app

A Progressive Web App is a type of application software that is delivered through the web. It is built using standard web technologies HTML, CSS, and JavaScript. It is expected to work on any platform that uses a standards-compliant browser, including desktop and mobile.

It is also known as a type of web page or web server. With the help of these PWA web pages, you can reach more customers for a business by marketing and promoting your business through web pages. You can also gain more customers by developing PWA by hiring a progressive web app development company. Nevina Infotech is a company that can help you to build your progressive web app with the help of its enthusiastic developers.

#progressive web app development company #progressive web app developers #progressive web app platform #progressive web app development services #progressive web app development