Codeforces 424 C Magic Formulas

來源:互聯網
上載者:User

標籤:des   style   http   java   os   strong   io   for   

Time Limit:2000MS     Memory Limit:262144KB    64bit IO Format:%I64d & %I64u

SubmitStatus Practice CodeForces 424C

Description

People in the Tomskaya region like magic formulas very much. You can see some of them below.

Imagine you are given a sequence of positive integer numbers p1,p2, ...,pn. Lets write down some magic formulas:

Here, "mod" means the operation of taking the residue after dividing.

The expression means applying the bitwisexor (excluding "OR") operation to integersx and y. The given operation exists in all modern programming languages. For example, in languages C++ and Java it is represented by "^", in Pascal — by "xor".

People in the Tomskaya region like magic formulas very much, but they don‘t like to calculate them! Therefore you are given the sequencep, calculate the value of Q.

Input

The first line of the input contains the only integer n (1?≤?n?≤?106). The next line containsn integers: p1,?p2,?...,?pn (0?≤?pi?≤?2·109).

Output

The only line of output should contain a single integer — the value of Q.

Sample Input

Input
31 2 3
Output
3

題意:如題。

思路:縱向分析,先是p1^……^pn。。。不說了,貼個網址,我覺得說的肯定比我清楚。http://www.tuicool.com/articles/InYrm2M

AC代碼:

#include <cstdio>#include <iostream>#include <algorithm>#include <cmath>#include <cstring>#include <stdlib.h>using namespace std;int p;int a[1000006];int main(){    int n;    scanf("%d",&n);    int ans=0;    for(int i=1;i<=n;i++){        scanf("%d",&p);        ans^=p;    }    for(int i=1;i<=n;i++){        a[i]=a[i-1]^i;        if(n%(2*i)!=0){            int x=n%(2*i);            if(x>=i){                ans^=a[i-1];                x-=i;            }            ans^=a[x];        }    }    printf("%d\n",ans);    return 0;}




相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.