LightOJ1336 Sigma Function (number of divisors and odd numbers) __ Math-theory/game

Source: Internet
Author: User

F (n) is the and of all the divisors of N, give you a number of n, let you ask from 1 to n in the number of F (n) are even numbers how many

Analysis:

The factor of number x and f (x) = (1+P1+P1^2+P1^3+...+P1^A1) * (1+P2+P2^2+...+P2^A2) *...* (1+pn+pn^2+...+pn^an);

Because even or even, odd-numbered or odd-numbered, odd-numbered even is even, all must have an odd number in each bracket, and then minus the divisors and odd numbers is the answer.

1. When x is 2, 2 of the corresponding brackets and must be an odd number, because even plus 1 must be odd.

2. Except for 2, all primes are odd, and to make x the corresponding number of other elements of the parentheses and the odd, you must ensure that X has even several of the factor, that AI must be even.

3. The number that satisfies the above two conditions is a square number, that is, the divisor and the odd number x, it must be a square number, and of course the number x multiplied by 2 is also satisfying the 2*x and odd numbers.


So just subtracting the n minus sqrt (n) and sqrt (N/2) is the answer. You can also find the number of squares within n, and the number of 2* squared number not more than n, and the answer is after the n minus.


The first method:

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
typedef long long LL;
int main ()
{
    int T;
    scanf ("%d", &t);
    for (int kase = 1; kase <= T; kase++)
    {
        ll n, sum;
        scanf ("%lld", &n);
        sum = n;
        Sum-= (int) sqrt (n);
        Sum-= (int) sqrt (N/2);
        printf ("Case%d:%lld\n", Kase, sum);
    }
    return 0;
}

The second method:

#include <stdio.h>
int main ()
{
    int T, Kase = 0;
    Long long N;
    scanf ("%d", &t);
    while (t--)
    {
        scanf ("%lld", &n);
        Long ans = 0;
        for (Long i = 1; i*i <= N; i++)
        {
            ans++;
            if (2*i*i<=n)
                ans++;
        }
        printf ("Case%d:%lld\n", ++kase, N-ans);
    }
    return 0;
}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.