Nyoj 527 ac_mm Play DotA

Source: Internet
Author: User
Tags dota

AC_MM play DotA time limit: +Ms | Memory Limit:65535KB Difficulty:2
Describe

We all know that ac_mm more like to play games, especially good at War3 this classic game. One day ac_mm came to the VS platform, ready to abuse rookie, happened to a careless will we ACM Captain abused ^_^, our captain this is not happy, said to out a difficult problem let ac_mm embarrassed a bit. The title description is this, given a positive integer n,n in the case of a binary representation (without leading 0 and sign bits) having a 1 and b 0, the Fibonacci sequence of the first a*b to 1314520 modulo the value of ans.

Note (Fibonacci series: f[0]=1,f[1]=1; f[n]=f[n-1]+f[n-2]; n>=2;)

Input
Input: There are several sets of test data, enter a positive integer n (n<1000000000);
Output
output: value of ans
Sample input
126
Sample output
52

The main idea is simple, the key is to take the binary system, conversion, draw x*y, when the table to take the remainder.

#include <cstdio>int a[260];int s[40];int shift1 (int n) {int num=1,i;s[0]=n%2;while (n/2!=0) {n/=2;s[num++]=n%2;} int t;for (i=0;i<=num/2;i++)//Here NUM/2 don't write num {t=s[i];s[i]=s[num-1-i];s[num-1-i]=t;} int X=0,y=0;for (i=0;i<num;i++) if (s[i]==1) X++;y=num-x;return x*y;} int main () {int n;a[0]=1,a[1]=1;for (int i=2;i<240;i++) a[i]= (A[i-1]+a[i-2])%1314520;while (~scanf ("%d", &n)) { printf ("%d\n", A[SHIFT1 (n)]);} return 0;}

Nyoj above the background database must have a problem, not to take the table when the surplus can also be too!!!

Nyoj 527 ac_mm Play DotA

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.