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