Table of Contents
Codeforces Round #157 (Div. 1) C. Little Elephant and LCM (数学、dp)
Home Backend Development PHP Tutorial Codeforces Round #157 (Div. 1) C. Little Elephant and LCM (mathematics, dp)_PHP tutorial

Codeforces Round #157 (Div. 1) C. Little Elephant and LCM (mathematics, dp)_PHP tutorial

Jul 13, 2016 am 10:14 AM
math

Codeforces Round #157 (Div. 1) C. Little Elephant and LCM (数学、dp)

C. Little Elephant and LCM time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standard output

The Little Elephant loves the LCM (least common multiple) operation of a non-empty set of positive integers. The result of the LCM operation of k positive integers x1,?x2,?...,?xk is the minimum positive integer that is divisible by each of numbers xi.

Let's assume that there is a sequence of integers b1,?b2,?...,?bn. Let's denote their LCMs as lcm(b1,?b2,?...,?bn) and the maximum of them as max(b1,?b2,?...,?bn). The Little Elephant considers a sequence b good, if lcm(b1,?b2,?...,?bn)?=?max(b1,?b2,?...,?bn).

The Little Elephant has a sequence of integers a1,?a2,?...,?an. Help him find the number of good sequences of integers b1,?b2,?...,?bn, such that for all i (1?≤?i?≤?n) the following condition fulfills: 1?≤?bi?≤?ai. As the answer can be rather large, print the remainder from dividing it by 1000000007 (109?+?7).

Input

The first line contains a single positive integer n (1?≤?n?≤?105) — the number of integers in the sequence a. The second line contains nspace-separated integers a1,?a2,?...,?an (1?≤?ai?≤?105) — sequence a.

Output

In the single line print a single integer — the answer to the problem modulo 1000000007 (109?+?7).

Sample test(s)
input
4
1 4 3 2
Copy after login
output
15
Copy after login
input
2
6 3
Copy after login
output
13
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
题意:
Copy after login
给你一个a序列,找出一个b序列,1?≤?bi?≤?ai,使得max(bi)=lcm(bi),问这样的bi序列有多少个。
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
思路:
Copy after login
先对a排序,枚举i=max(bi),对i因式分解,那么大于等于i的部分很好处理,直接pow_mod()相减,小于i的部分就任意取一个约束就够了。
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
代码:
Copy after login
<pre class="code">#include <iostream>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include
#define INF 0x3f3f3f3f
#define maxn 100005
#define mod 1000000007
typedef long long ll;
using namespace std;

int n;
int a[maxn];

ll pow_mod(ll x,ll n)
{
    ll res = 1;
    while(n)
    {
        if(n&1) res = res * x %mod;
        x = x * x %mod;
        n >>= 1;
    }
    return res;
}
void solve()
{
    int i,j;
    ll ans=0,res;
    sort(a+1,a+n+1);
    for(i=1;i<=a[n];i++) // 枚举答案
    {
        vector<int>fac;
        for(j=1;j*j<=i;j++) // factor
        {
            if(i%j==0)
            {
                fac.push_back(j);
                if(j*j!=i) fac.push_back(i/j);
            }
        }
        sort(fac.begin(),fac.end());
        int pos,pre=1;
        res=1;
        for(j=1;j<fac.size();j++)
        {
            pos=lower_bound(a+1,a+n+1,fac[j])-a;
            res*=pow_mod(j,pos-pre);
            res%=mod;
            pre=pos;
        }
        ans+=res*((pow_mod(j,n-pre+1)-pow_mod(j-1,n-pre+1)+mod)%mod);
        ans%=mod;
    }
    printf("%I64d\n",ans);
}
int main()
{
    int i,j;
    while(~scanf("%d",&n))
    {
        for(i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
        }
        solve();
    }
    return 0;
}
Copy after login

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/907369.htmlTechArticleCodeforces Round #157 (Div. 1) C. Little Elephant and LCM (数学、dp) C. Little Elephant and LCMtime limit per test4 secondsmemory limit per test256 megabytesinputstandard in...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

AI subverts mathematical research! Fields Medal winner and Chinese-American mathematician led 11 top-ranked papers | Liked by Terence Tao AI subverts mathematical research! Fields Medal winner and Chinese-American mathematician led 11 top-ranked papers | Liked by Terence Tao Apr 09, 2024 am 11:52 AM

AI is indeed changing mathematics. Recently, Tao Zhexuan, who has been paying close attention to this issue, forwarded the latest issue of "Bulletin of the American Mathematical Society" (Bulletin of the American Mathematical Society). Focusing on the topic "Will machines change mathematics?", many mathematicians expressed their opinions. The whole process was full of sparks, hardcore and exciting. The author has a strong lineup, including Fields Medal winner Akshay Venkatesh, Chinese mathematician Zheng Lejun, NYU computer scientist Ernest Davis and many other well-known scholars in the industry. The world of AI has changed dramatically. You know, many of these articles were submitted a year ago.

heptagon number heptagon number Sep 24, 2023 am 10:33 AM

Aheptagonalnumberisanumberwhichcanberepresentedasaheptagon.Aheptagonisapolygonwith7sides.Aheptagonalnumbercanberepresentedasacombinationofsuccessivelayersofheptagon(7-sidedpolygon).Heptagonalnumbercanbebetterexplainedwiththebelowfigures. therefore,

Groundbreaking CVM algorithm solves more than 40 years of counting problems! Computer scientist flips coin to figure out unique word for 'Hamlet' Groundbreaking CVM algorithm solves more than 40 years of counting problems! Computer scientist flips coin to figure out unique word for 'Hamlet' Jun 07, 2024 pm 03:44 PM

Counting sounds simple, but in practice it is very difficult. Imagine you are transported to a pristine rainforest to conduct a wildlife census. Whenever you see an animal, take a photo. Digital cameras only record the total number of animals tracked, but you are interested in the number of unique animals, but there is no statistics. So what's the best way to access this unique animal population? At this point, you must be saying, start counting now and finally compare each new species from the photo to the list. However, this common counting method is sometimes not suitable for information amounts up to billions of entries. Computer scientists from the Indian Statistical Institute, UNL, and the National University of Singapore have proposed a new algorithm - CVM. It can approximate the calculation of different items in a long list.

MLP was killed overnight! MIT Caltech and other revolutionary KANs break records and discover mathematical theorems that crush DeepMind MLP was killed overnight! MIT Caltech and other revolutionary KANs break records and discover mathematical theorems that crush DeepMind May 06, 2024 pm 03:10 PM

Overnight, the machine learning paradigm is about to change! Today, the infrastructure that dominates the field of deep learning is the multilayer perceptron (MLP), which places activation functions on neurons. So, beyond that, are there any new routes we can take? Just today, teams from MIT, Caltech, Northeastern University and other institutions released a new neural network structure-Kolmogorov–Arnold Networks (KAN). The researchers made a simple change to the MLP by moving the learnable activation function from the nodes (neurons) to the edges (weights)! Paper address: https://arxiv.org/pdf/2404.19756 This change seems baseless at first glance

Does AI painting still need to know mathematics? Does AI painting still need to know mathematics? Jun 12, 2023 pm 02:05 PM

Vision With the development of artificial intelligence technology, AI painting has become a hot topic at the moment. By using deep learning algorithms, artificial intelligence can generate realistic images to create stunning works of art. Behind these amazing works, it is inseparable from the support of mathematical knowledge. Mathematical models play a vital role in AI painting. On the one hand, mathematical models are used to describe and represent image information, allowing computers to understand and process images. On the other hand, mathematical models are also used to train deep learning models to achieve automatic generation of images. Deep learning model brings high-quality image generation. Deep learning model is the core part of AI painting. It identifies and simulates the characteristics of images by learning a large amount of image data, and through multi-level data processing

Is the mathematics behind the diffusion model too difficult to digest? Google makes it clear with a unified perspective Is the mathematics behind the diffusion model too difficult to digest? Google makes it clear with a unified perspective Apr 11, 2023 pm 07:46 PM

In recent times, AI painting has been very popular. While you are marveling at AI’s painting capabilities, what you may not know is that the diffusion model plays a big role in it. Take the popular model OpenAI's DALL·E 2 as an example. Just enter a simple text (prompt) and it can generate multiple 1024*1024 high-definition images. Not long after DALL·E 2 was announced, Google subsequently released Imagen, a text-to-image AI model that can generate realistic images of the scene from a given text description. Just a few days ago, Stability.Ai publicly released the text generation image model Stable Diffusi

'Mathematical noob' ChatGPT understands human preferences very well! Generating random numbers online is the ultimate answer to the universe 'Mathematical noob' ChatGPT understands human preferences very well! Generating random numbers online is the ultimate answer to the universe Apr 01, 2023 am 11:48 AM

ChatGPT also understands human tricks when it comes to generating random numbers. ChatGPT may be a bullshit artist and a spreader of misinformation, but it is not a "mathematician"! Recently, Colin Fraser, a Meta data scientist, discovered that ChatGPT cannot generate truly random numbers, but is more like "human random numbers." Through experiments, Fraser concluded: "ChatGPT likes the numbers 42 and 7 very much." Netizens said that this means that humans like these numbers very much. ChatGPT also loves "The Ultimate Answer to the Universe". In his test, the prompt entered by Fraser is as follows: "Pick a random number

Working during the day and doing research at night, Google Brain research scientists solved a conjecture that has puzzled the mathematical community for decades. Working during the day and doing research at night, Google Brain research scientists solved a conjecture that has puzzled the mathematical community for decades. Apr 12, 2023 am 09:49 AM

In mid-October 2022, Justin Gilmer flew from California to New York to visit his former mentor Michael Saks, a mathematician at Rutgers University, on the East Coast. During the reminiscence, they did not talk about mathematics. In fact, Gilmer hasn’t thought seriously about math since earning his PhD at Rutgers University in 2015. At that time, he decided not to pursue a career in academia and began to teach himself programming. Over dinner with Saks, Gilmer told his mentor about his work at Google: machine learning and artificial intelligence. As he walked along the path on campus, Gilmer recalled that in 2013, he spent more than a year walking on this path.

See all articles