"Three Questions of number theory" simple title competition ranking Factorization

Source: Internet
Author: User

These three ideas are not complicated, put together

Simple problem surface

Calculation

Because the final result may exceed the range of int, take the result of the operation to modulo 1000000007.

An integer t (T <= 200000) that represents the number of data groups. Two integers per line m, N. (0 < M <= N <= 2000)

Analysis

It's the combination number. C (n,m)

Think of a layer of a layer of the cycle, each time the previous number +1 start, not equivalent to the previous cycle, there is a number is selected, and the remaining number from +1, the equivalent of in this layer of the loop to pick out AH.

Code
#include <bits/stdc++.h>using namespacestd;#defineN 2020#definell Long Long#defineMoD 1000000007ll T,n,m;ll C[n][n];intMain () {c[1][0]=c[1][1]=1;  for(LL i=2; i<= .; i++) {c[i][0]=1;  for(LL j=1; j<= .; j + +) C[i][j]= (c[i-1][j]+c[i-1][j-1])%MoD; } scanf ("%lld",&t);  while(t--) {scanf ("%lld%lld",&m,&N); printf ("%lld\n", C[n][m]); }    return 0;}
Competition ranking Problem surface

N students participate in the contest, ask how many ranking situation, allow to appear side-by-side situation (N<=12)

Analysis

The teacher put the water, the original problem n<=200, but the idea is the same

Consider who should be the first, for example, for n=4 is, you can choose one of the four when the first, you can select two, choose Three, choose Four

So there are Ans[4]=c (4,1) *ans[3]+c (4,2) *ans[2]+c (4,3) *ans[1]+c (bis) *ans[0]

So n can be similar to calculate, can get such a calculation way

Code
#include <bits/stdc++.h>using namespacestd;#defineN 20#definell Long Longll N,a[n],c[n][n];ll Dfs (ll x) {if(x==0)return 1; if(A[x])returnA[x];  for(intI=1; i<=x;i++) A[x]+=c[x][i]*dfs (xi); returna[x];}intMain () {CIN>>N; c[1][1]=c[1][0]=1;  for(LL i=2; i<= -; i++) {c[i][0]=1;  for(LL j=1; j<= -; j + +) C[i][j]=c[i-1][j]+c[i-1][j-1]; } cout<<DFS (n);}
Factorization problem surface

Otosakayuu recently made a flag for Nao Tomori to save the world, so he thought about a maths problem. There is a positive integer sequence a1,a2...an. Defines the number of different mass factors for the function f (x) for x. F (A1), F (A2) ... f (an).

The first line contains a positive integer that represents N. Next n rows, each line contains a positive integer AI. 1<=n<=1000000,2<=ai<=1000000

Analysis

Only O (1) to be done, on the linear sieve to add a special sentence

For a prime[j] sieve out of the number, consider and prime[j] multiplied by whether I can be divisible prime[j], if possible, prove I*prime[j] has a prime[j] this factor, if not, then the number of its quality factor will be on the basis of the number of the I of the qualitative factor + 1

Code
#include <bits/stdc++.h>using namespacestd;#defineN 1000100#defineMX 1000010#definell Long Longll T,n,cnt,c,k,mm;ll S[n],f[n],v[n],num[n],prime[n];voidPrimesintN) {num[1]=1;  for(intI=2; i<=n;i++)    {        if(!V[i]) {prime[++cnt]=i; V[i]=i;num[i]=1; }         for(intj=1; j<=cnt;j++)        {            if(prime[j]>v[i]| | prime[j]>n/i) Break; V[i*prime[j]]=Prime[j]; if(I%prime[j]) num[i*prime[j]]=num[i]+1; Elsenum[i*prime[j]]=Num[i]; }    }}intMain () {scanf ("%lld",&t);    Primes (MX);  for(intI=1; i<=t;i++) {scanf ("%lld",&k); printf ("%lld\n", Num[k]); }    }

"Three Questions of number theory" simple title competition ranking Factorization

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.