题目链接:

http://acm.hdu.edu.cn/showproblem.php?pid=3524

题目大意:

求i^2 mod 2^n有多少可能

解题思路:

先打表,求出n较小的时候的数据

n 1 2 3 4 5 6 7 8 9 10 11 12 13
答案 2 2 3 4 7 12 23 44 87 127 343 684 1367

发现差值分别是 0 1 1 3 5 11 21 43 85 171 341 683,

规律是后一项是前一项的两倍减一或者两倍加一,一开始发现这个规律准备从这里着手,但是还是求不出第n项

第n项就等于2+上述差值的第n-1项前缀和(因为差值是从第二项开始的)

上述差值的前缀和为 0 1 2 5 10 21 42 85 170 341 682

比如n = 3,ans[3] = 2 + 1,1就是第2项前缀和

n = 5, ans[5] = 2 + 5 = 7,5就是第3项前缀和

然后会发现前缀和有规律,后一项是前一项的两倍或者两倍+1,按照这个规律,可以暴力出前缀和+2就是答案,直接打表模上10007,求出10万项先看看

发现ans[10007] = ans[1] = 2     ans[10008] = ans[2] = 2     ans[10009] = ans[3] = 3,之后的每一项都是这样

找到循环节

那么直接求出前10006项即可,对于n直接模上10006即可,注意模上10006之后会出现等于0的情况,可以将ans[0] = ans[10006],也可以通过特殊的取模运算。

对于n 求n - 1 % 10006 + 1,那么就是他的对应项数,10006对应着就是10006,10007 对应 1

 #include<bits/stdc++.h>
using namespace std;
int a[];
int main()
{
a[] = ;a[] = ;
int v = ;
for(int i = ; i <= ; i++)
{
a[i] = a[i - ] * + v;
v = !v;
a[i] %= ;
//cout<<i<<" "<<a[i]<<endl;
}
int n;
int T, cases = ;
cin >> T;
while(T--)
{
//将n模上10006转化到10006上面
cin >> n;
n = (n - ) % + ;
printf("Case #%d: %d\n", ++cases, (a[n] + ) % );
}
return ;
}

hdu-3524 Perfect Squares---打表+找规律+循环节的更多相关文章

  1. HDU 4731 Minimum palindrome 打表找规律

    http://acm.hdu.edu.cn/showproblem.php?pid=4731 就做了两道...也就这题还能发博客了...虽然也是水题 先暴力DFS打表找规律...发现4个一组循环节.. ...

  2. CF R 633 div 1 1338 C. Perfect Triples 打表找规律

    LINK:Perfect Triples 初看这道题 一脸懵逼.. 完全没有思路 最多就只是发现一点小规律 即. a<b<c. 且b的最大的二进制位一定严格大于a b的最大二进制位一定等于 ...

  3. HDU 3032 (SG打表找规律)

    题意: 有n堆石子,alice先取,每次可以选择拿走一堆石子中的1~x(该堆石子总数) ,也可以选择将这堆石子分成任意的两堆.alice与bob轮流取,取走最后一个石子的人胜利. 思路: 因为数的范围 ...

  4. 数学--数论--HDU - 6124 Euler theorem (打表找规律)

    HazelFan is given two positive integers a,b, and he wants to calculate amodb. But now he forgets the ...

  5. 2019南昌网络赛H The Nth Item(打表找询问循环节 or 分段打表)

    https://nanti.jisuanke.com/t/41355 思路 从fib循环节入手,\(O(1e7log(1e9))\),tle 因为只需要输出所有询问亦或后的结果,所以考虑答案的循环节, ...

  6. hdu 3032 Nim or not Nim? (SG函数博弈+打表找规律)

    Nim or not Nim? Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Sub ...

  7. HDU 5753 Permutation Bo (推导 or 打表找规律)

    Permutation Bo 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5753 Description There are two sequen ...

  8. HDU 5795 A Simple Nim(SG打表找规律)

    SG打表找规律 HDU 5795 题目连接 #include<iostream> #include<cstdio> #include<cmath> #include ...

  9. HDU 4861 Couple doubi (数论 or 打表找规律)

    Couple doubi 题目链接: http://acm.hust.edu.cn/vjudge/contest/121334#problem/D Description DouBiXp has a ...

随机推荐

  1. poj 2572 Hard to Believe, but True!

    Hard to Believe, but True! Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3537   Accep ...

  2. h5页面ios,双击向上滑动,拖拽到底部还能继续拖拽(露出黑色背景)

    h5页面ios,双击向上滑动,拖拽到底部还能继续拖拽 标签: 手机 2016-02-02 18:09 696人阅读 评论(0) 收藏 举报   在ios下,双击屏幕某些地方,滚动条会自动向上走一段. ...

  3. codeforces 638B—— Making Genome in Berland——————【类似拓扑排序】

    Making Genome in Berland time limit per test 1 second memory limit per test 256 megabytes input stan ...

  4. HDU 5700——区间交——————【线段树+枚举】

    区间交 Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submiss ...

  5. 常用工具说明--GitHub团队项目合作流程

    注:其中 零.一.七 是由团队项目负责人来完成的.开发人员只要从 二 开始就行了. 零.前期准备: 首先把队友直接push的权限关掉,即设置成Read.这样可以防止队友误操作,未经审核就把代码push ...

  6. 批量查找ip地址归属地脚本

    #!/bin/bash ip_list=`cat $1` for i in $ip_listdocurl http://www.ip.cn/index.php?ip=$idoneexit 0

  7. java爬取百度首页源代码

    爬虫感觉挺有意思的,写一个最简单的抓取百度首页html代码的程序.虽然简单了一点,后期会加深的. package test; import java.io.BufferedReader; import ...

  8. 跨平台 GUI可视化 网络调试工具

    mNetAssisthttp://blog.chinaunix.net/uid-21977056-id-4310527.htmlhttps://github.com/busyluo/mNetAssis ...

  9. document.getElementsByTagName

    var elems = document.forms[form_name].getElementsByTagName("INPUT"); getElementsByTagName( ...

  10. Spring学习笔记:Spring整合Mybatis学习PPT(三:整合思路)

    三.Spring-Mybatis的整合思路