Rokua number theory {water problem} set

Source: Internet
Author: User

1. Sequencing of P1327 sequences

Title Description

Given a sequence {an}, this sequence satisfies Ai≠aj (I≠J), and now requires you to order this sequence from small to large, each time you allow you to exchange any one of them, how many times do I need to exchange?

input/output format

Input format:

The first line, positive integer n (n<=100,000).

Following several lines, total n number, separated by a space, indicating the sequence {an}, arbitrary -231<ai<231.

Output format:

Only one row, containing a number, represents the minimum number of interchanges.

input/Output sampleInput Sample # #:
88 23 4 16 77-5 53 100
Sample # # of output:
 5  


I thought it was in reverse order.
Find a swap chain, move from the original position to the new location, and end up with a ring
Span style= "FONT-SIZE:16PX; Color: #0000ff; " > Note every time you add a cnt-1, because the last two are in the correct place
code to implement the original location package structure , sort, flag represents a return, go on.
#include <iostream> #include <cstdio> #include <algorithm>using namespace std;const int n=100005; struct node{    int o,w;} A[n];bool CMP (const node &A,CONST node &b) {    return A.W<B.W;} int n,flag[n],ans=0;    Guiweiint Main () {    scanf ("%d", &n);    for (int i=1;i<=n;i++) {        scanf ("%d", &a[i].w); a[i].o=i;    }    Sort (a+1,a+1+n,cmp);    for (int i=1;i<=n;i++) {        if (flag[i]==0) {            int now=i,cnt=0;            while (flag[now]==0) {                cnt++;                Flag[now]=1;                NOW=A[NOW].O;            }            ans+=cnt-1;        }    }    Cout<<ans;}

 2.p1630 Summation
Title Description

The remainder of the 1^b+2^b+......+a^b and divided by 10000.

input/output format

Input format:

The first line contains a positive integer n, representing a total of n groups of test data;

Next n rows, each row contains two positive integers a and B.

"Data Size"

For 30% of the data, meet the n<=10,a,b<=1000;

For 100% of the data, meet the n<=100,a,b<=1000000000;

Output format:

A total of n rows, one corresponding answer per line.

input/Output sampleInput Sample # #:
12 3
Sample # # of output:
 9  
-- ----------------------------------------------------------------------------------------
violence can only take 30 points
use F[i] to represent the results of i^b%10000, consider each fi contribution to the answer
complexity O (10000*logb*n)
do not use long long can also
#include <iostream> #include <cstdio> #include <algorithm> #include <cstring>using namespace Std;const int mod=10000,n=10005;typedef Long long ll;int n;ll a,b;ll f[n];ll powmod (ll a,ll b) {    ll ans=1;    for (; b;b>>=1,a= (a*a)%mod)        if (b&1) ans= (ans*a)%mod;    return ans;} ll solve (ll A,ll b) {for    (int i=1;i<=mod;i++)        f[i]=powmod (i,b);    ll Div=a/mod,mod=a%mod;    ll Ans=0;    for (int i=1;i<=mod;i++) {        ans= (ans+div*f[i])%mod;        if (i<=mod) ans= (ans+f[i])%mod;    }    return ans;} int main () {    scanf ("%d", &n);    for (int i=1;i<=n;i++) {        memset (f,0,sizeof (f));        scanf ("%lld%lld", &a,&b);        Cout<<solve (A, b) << "\ n";    }}

An approximate study of 3.p1403
Title Description

The scientists ' exploration of the Samuel Planet has been enriched with energy reserves, making it possible for the long-time operations of large computers in the space station to be "Samuel2". As a result of the hard work of last year, Xiao Lian allowed to use "Samuel2" for mathematical research.

In a recent study of the number of issues related to the sum, he counted the number of approximate numbers of each positive n and expressed it in F (n). Now Xiao Lian hopes to use "Samuel2" to count the sum of f (1) to F (N) and M.

F (n) represents an approximate number of N, which is now given N, which requires the sum of f (1) to F (n) to be calculated.

input/output format
Input format:

Enter a line, an integer n

Output format:

Outputs an integer representing the sum

input/Output sampleInput Sample # #:
3
Sample # # of output:
5
   ----- -------------------------------
I started with a unique decomposition to add about a few numbers and sums
See is to ask for 1~n, can be like the Sieve method, suddenly think, consider the contribution of each number is n/i, too water, ━━ ( ̄ー ̄*| | | ━━
#include <iostream>usingnamespace  std; int n,ans=0; int Main () {    cin>>N;      for (int i=1; i<=n;i++) ans+=n/i;    cout<<

Rokua number theory {water problem} set

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.