Euler project: multiples of 3 and 5 c ++

I have implemented the following code for the mentioned topic. The results are incorrect in c ++. the same code works correctly in python why?

for (int i = 1; i <1000; i++) {
    if (i % three == 0 || i%five==0) {
        sum_3 += i;
    }

}

dataset – Import images of multiples of FITS format

I want to import several url images that are inside a .txt but I receive an error, it is not a valid URL file, directory or specification

In[1]: = F = Import["/home/hp-pc/Desktop/Fits_3.txt", "Text"]

Outside[1]= {"" https: //dr12.sdss.org/sas/dr12/boss/photoObj/frames/301/ 
2864/1 / frame-u-002864-1-0011.fits.bz2  "
 "https: //dr12.sdss.org/sas/dr12/boss/photoObj/frames/301/2864/1/ 
frame-g-002864-1-0011.fits.bz2  "
 "https: //dr12.sdss.org/sas/dr12/boss/photoObj/frames/301/2864/1/ 
fram / boss / photoObj / frames / 301/6074/5 / 
frame-z-006074-5-0011.fits.bz2  ""}

In[2]: = First[Import[#, "FITS"]]& / @ {F}

During the evaluation of In[2]: = Import :: chtype: First argument "https://dr12.sdss.org/sas/dr12/boss/photoObj/frames/301/2864/1/frame-u-002864-1-0011.fits.bz2"
During the evaluation of In[2]: = First :: normal: a non-atomic expression is expected in position 1 in First[$Failed].

Outside[2]= {First[$Failed]}

And I really do not know what the error is.

mysql: performance, slow loading of queries with multiples on the left

I'm struggling a lot with a great doctrine consultation, there are 17,000 contacts in the database and about 1 million rows for statistics and orders.

As you can see, there are many calculated values, I really need these values ​​to perform the filtering.

At first I tried to make that query with DQL, but it's so bad in terms of performance, the query takes more than 15 or 30 seconds.

The objective is to have 17,000 rows for each contact with their calculated values.

If someone can give me some advice, I am sure that I am not the only one who needs to make such kind of consultations.

Thanks in advance πŸ™‚

This is the doctrine query builder.

    $ qb = $ this-> createQueryBuilder (& # 39; contact & # 39;);

$ qb-> select ("contact.id");
$ qb-> addSelect ("contact.source");
$ qb-> addSelect ("contact.updatedAt");
$ qb-> addSelect ("contact.createdAt");

// orders
$ qb-> addSelect ("COUNT (distinct shop_order.id) AS totalOrders");
$ qb-> addSelect ("SUM (distinct shop_order.price) AS totalSpentOrders");
$ qb-> addSelect ("AVG (different shop_order.price) AS averageCart");
$ qb-> addSelect ("MAX (shop_order.createdAt) AS lastOrderDatedAt");
$ qb-> addSelect ("MIN (shop_order.createdAt) AS firstOrderDatedAt");
$ qb-> addSelect ("last_shop_order.price AS totalSpentLastOrder");

// order statuses
$ qb-> addSelect ("COUNT (DISTINCT (CASE WHEN shop_order.status =". Order :: STATUS_WAITING. "THEN shop_order.id ELSE: empty END)) AS totalOrdersWaitingOrError");
$ qb-> addSelect ("COUNT (DISTINCT (CASE WHEN shop_order.status =". Order :: STATUS_PAID. "THEN shop_order.id ELSE: empty END)) AS totalOrdersPaid");
$ qb-> addSelect ("COUNT (DISTINCT (CASE WHEN shop_order.status =". Order :: STATUS_DELIVERED. "then shop_order.id ELSE: empty END)) AS totalOrdersDelivered");
$ qb-> addSelect ("COUNT (DISTINCT (CASE WHEN shop_order.status =". Order :: STATUS_PAYMENT_ERROR. "THEN shop_order.id ELSE: empty END)) AS totalOrdersPaymentError");
$ qb-> addSelect ("COUNT (DISTINCT (CASE WHEN shop_order.status =". Order :: STATUS_SHIPPED. "THEN shop_order.id ELSE: empty END)) AS totalOrdersShipped");
$ qb-> addSelect ("COUNT (DISTINCT (CASE WHEN shop_order.status =". Order :: STATUS_ABORTED. "THEN shop_order.id ELSE: empty END)) AS totalOrdersAborted");

$ qb-> leftJoin ("contact.orders", "shop_order", Join :: WITH, "shop_order.isValid = 1 AND shop_order.contact = contact");
$ qb-> leftJoin ("contact.orders", "last_shop_order", Join :: WITH, "last_shop_order = FIRST (SELECT lso FROM App: Order lso WHERE lso.isValid = 1 AND lso.contact = contact ORDER BY lso.createdAt DESC) ");

// order cart
$ qb-> leftJoin ("shop_order.cart", "cart");
$ qb-> leftJoin ("cart.productCarts", "product_carts");
$ qb-> leftJoin ("product_carts.product", "product");

// abandoned cars
$ qb-> addSelect ("COUNT (distinct abandonned_cart.id) AS totalAbandonnedCarts");
$ qb-> addSelect ("SUM (different abandonned_product.price) AS totalAmountAbandonnedCarts");

$ qb-> leftJoin ("contact.carts", "abandonned_cart");
$ qb-> leftJoin ("abandonned_cart.shopOrder", "abandonned_shop_order");
$ qb-> leftJoin ("abandonned_cart.productCarts", "abandonned_product_cart");
$ qb-> leftJoin ("abandonned_product_cart.product", "abandonned_product");
$ qb-> andWhere ("abandonned_shop_order.id IS NULL");

$ qb-> addSelect ("SUM (different last_abandonned_cart.amount) AS totalAmountLastAbandonnedCart");

$ qb-> leftJoin ("contact.carts", "last_abandonned_cart", Join :: WITH, "last_abandonned_cart = FIRST (SELECT FROM App: Cart lac LEFT JOIN lac.shopOrder lacso WHERE lacso IS NULL AND lac.contact = contact ORDER BY lac.createdAt DESC) ");
$ qb-> leftJoin ("last_abandonned_cart.productCarts", "last_abandonned_product_cart");
$ qb-> leftJoin ("last_abandonned_product_cart.product", "last_abandonned_product");

// behavior
$ qb-> addSelect ("COUNT (DISTINCT (CASE WHEN contact_stat.type =". ContactStat :: TYPE_EMAIL_SENT. "THEN contact_stat.id ELSE: Empty END)) AS totalEmailSent");
$ qb-> addSelect ("COUNT (DISTINCT (CASE WHEN contact_stat.type =". ContactStat :: TYPE_EMAIL_CLICKED. "THEN contact_stat.id ELSE: empty END)) AS totalEmailClicked");
$ qb-> addSelect ("COUNT (DISTINCT (CASE WHEN contact_stat.type =". ContactStat :: TYPE_EMAIL_OPENED. "THEN contact_stat.id ELSE: empty END)) AS totalEmailOpened");
$ qb-> addSelect ("(COUNT (DISTINCT (CASE WHEN contact_stat.type =". ContactStat :: TYPE_EMAIL_CLICKED. "then contact_stat.id ELSE: empty END)) / COUNT (DISTINCT (CASE WHEN contact_stat.type =". ContactStat :: TYPE_EMAIL_SENT. "THEN contact_stat.id ELSE: empty END))) * 100 AS emailClickedRate");
$ qb-> addSelect ("(COUNT (DISTINCT (CASE WHEN contact_stat.type =". ContactStat :: TYPE_EMAIL_OPENED. "then contact_stat.id ELSE: empty END)) / COUNT (DISTINCT (CASE WHEN contact_stat.type =". ContactStat :: TYPE_EMAIL_SENT. "THEN contact_stat.id ELSE: empty END))) * 100 AS emailOpenedRate");
$ qb-> leftJoin ("contact.contactStats", "contact_stat");

// other contact information
$ qb-> leftJoin ("contact.address", "address");
$ qb-> leftJoin ("contact.contactOperations", "contact_operation");
$ qb-> leftJoin ("contact_operation.operation", "operation");
$ qb-> leftJoin ("contact.accountTypes", "account_type");
$ qb-> leftJoin ("contact.medicalInformation", "medical_information");

$ qb-> setParameter ("empty", null);

$ qb-> orderBy ("contact.updatedAt", "DESC");
$ qb-> groupBy ("contact.id");

I tried to remove some of the joins and calculated values, this is the SQL query:

SELECT
c0_.id AS id_0,
c0_.email AS email_1,
c0_.first_name AS first_name_2,
c0_.last_name AS last_name_3,
c0_.type AS type_4,
c0_.updated_at AS updated_at_5,
c0_.source AS source_6,
c0_.created_at AS created_at_7,
a1_.postcode AS postcode_8,
a1_.country AS country_9,
m2_.skin_type AS skin_type_10,
c0_.is_optin_sms AS is_optin_sms_11
SINCE
contact c0_
ADDRESS LEFT a1_ ON c0_.address_id = a1_.id
JOIN THE LEFT medical_info m2_ ON c0_.id = m2_.contact_id
LEFT GASKET contact_operation c3_ ON c0_.id = c3_.contact_id
Operation LEFT JOIN o4_ ON c3_.operation_id = o4_.id
LEFT JOIN account_type_contact a6_ ON c0_.id = a6_.contact_id
LEFT JOIN account_type a5_ ON a5_.id = a6_.account_type_id
JOIN THE LEFT contact_stat c7_ ON c0_.id = c7_.contact_id
LEFT COMBINATION shop_order s8_ ON c0_.id = s8_.contact_id
Y (
s8_.is_valid = 1
And s8_.contact_id = c0_.id
)
LEFT COMBINATION shop_order s9_ ON c0_.id = s9_.contact_id
Y (
s9_.id = (
SELECT
s10_.id
SINCE
shop_order s10_
WHERE
s10_.is_valid = 1
And s10_.contact_id = c0_.id
ORDER BY
s10_.created_at DESC
LIMIT
one
)
) LEFT JOIN carriage c11_ ON s8_.cart_id = c11_.id
LEFT JOIN product_cart p12_ ON c11_.id = p12_.cart_id
LEFT JOIN product p13_ ON p12_.product_id = p13_.id
LEFT JOIN carriage c14_ ON c0_.id = c14_.contact_id
LEFT JOIN shop_order s15_ ON c14_.id = s15_.cart_id
Y (
s15_.id is null
And s15_.contact_id = c0_.id
)
GROUP BY
c0_.id
ORDER BY
c0_.updated_at DESC

The query takes more than 8 seconds.

There is the explanation of the query.

enter the description of the image here


Why not impute the equal numbers between arra arrangements and multiples ..?





Untitled document






enter the description of the image here

Algorithms: count the number of multiples of the number A that perfectly divides the number B

What is the best way to count the number of multiples of the number A that perfectly divides the number B.

This is the secondary problem for one of the questions I am solving in codechef.
This is the best thing that comes to mind.

int func (int A, int B) {
int res = 0;
int i = 1;
while (A * i <= B) {
yes (! (B% (A * i))) {
res ++;
}
i ++;
}
come back;
}

However, this is the waiting time for some of the cases. They tell me that this can be solved in O (sqrt (n)). Any help would be appreciated.