Perfect Squares

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 582    Accepted Submission(s): 323

Problem Description
A number x is called a perfect square if there exists an integer b 
satisfying x=b^2. There are many beautiful theorems about perfect squares in mathematics. Among which, Pythagoras Theorem is the most famous. It says that if the length of three sides of a right triangle is a, b and c respectively(a < b <c), then a^2 + b^2=c^2. 
In this problem, we also propose an interesting question about perfect squares. For a given n, we want you to calculate the number of different perfect squares mod 2^n. We call such number f(n) for brevity. For example, when n=2, the sequence of {i^2 mod 2^n} is 0, 1, 0, 1, 0……, so f(2)=2. Since f(n) may be quite large, you only need to output f(n) mod 10007.
 
Input
The first line contains a number T<=200, which indicates the number of test case.
Then it follows T lines, each line is a positive number n(0<n<2*10^9).
 
Output
For each test case, output one line containing "Case #x: y", where x is the case number (starting from 1) and y is f(x).
 
Sample Input
2
1
2
 
Sample Output
Case #1: 2
Case #2: 2
 
Source
题意:
求i^2%2^n有多少个不同的结果(i>=0,n是给出的数),最后总数%10007;
代码:
/*
就是打表+找规律
n为偶数,f[n]=(2^(n-1)-2)/3+2;
n为奇数,f[n]=(2^(n-1)-1)/3+2;
这里需要解决的只有除法取余: 费马小定理(Fermat Theory)是数论中的一个重要定理,其内容为: 假如p是质数,且gcd(a,p)=1,那么
a(p-1)≡1(mod p)。即:假如a是整数,p是质数,且a,p互质(即两者只有一个公约数1),那么a的
(p-1)次方除以p的余数恒等于1。 1.可以用乘法的逆来解决,当然可知当成定理来用(a/b)%mod=(a*b^(mod-2))%mod,mod为素数
原理是费马小定理:a^(mod-1)%mod=1,又a^0%mod=1,所以a^(-1)=a^(mod-2),推出a/b=a*b^(-1)=a*b^(mod-2)
*/
#include<iostream>
#include<cmath>
using namespace std;
const int mod=;
int solve(int a,int n)
{
if(n==) return ;
int x=solve(a,n/);
long long ans=(long long)x*x%mod;
if(n&) ans=ans*a%mod;
return (int)ans;
}
int main()
{
int t,n;
cin>>t;
for(int i=;i<=t;i++){
cin>>n;
cout<<"Case #"<<i<<": ";
int ans;
if(n&) ans=((solve(,n-)-)*solve(,mod-))%mod+;
else ans=((solve(,n-)-)*solve(,mod-))%mod+;
cout<<ans<<endl;
}
return ;
}

HDU3524 数论的更多相关文章

  1. Codeforces Round #382 Div. 2【数论】

    C. Tennis Championship(递推,斐波那契) 题意:n个人比赛,淘汰制,要求进行比赛双方的胜场数之差小于等于1.问冠军最多能打多少场比赛.题解:因为n太大,感觉是个构造.写写小数据, ...

  2. NOIP2014 uoj20解方程 数论(同余)

    又是数论题 Q&A Q:你TM做数论上瘾了吗 A:没办法我数论太差了,得多练(shui)啊 题意 题目描述 已知多项式方程: a0+a1x+a2x^2+..+anx^n=0 求这个方程在[1, ...

  3. 数论学习笔记之解线性方程 a*x + b*y = gcd(a,b)

    ~>>_<<~ 咳咳!!!今天写此笔记,以防他日老年痴呆后不会解方程了!!! Begin ! ~1~, 首先呢,就看到了一个 gcd(a,b),这是什么鬼玩意呢?什么鬼玩意并不 ...

  4. hdu 1299 Diophantus of Alexandria (数论)

    Diophantus of Alexandria Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java ...

  5. 【BZOJ-4522】密钥破解 数论 + 模拟 ( Pollard_Rho分解 + Exgcd求逆元 + 快速幂 + 快速乘)

    4522: [Cqoi2016]密钥破解 Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 290  Solved: 148[Submit][Status ...

  6. bzoj2219: 数论之神

    #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #i ...

  7. hdu5072 Coprime (2014鞍山区域赛C题)(数论)

    http://acm.hdu.edu.cn/showproblem.php?pid=5072 题意:给出N个数,求有多少个三元组,满足三个数全部两两互质或全部两两不互质. 题解: http://dty ...

  8. ACM: POJ 1061 青蛙的约会 -数论专题-扩展欧几里德

    POJ 1061 青蛙的约会 Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%lld & %llu  Descr ...

  9. 数论初步(费马小定理) - Happy 2004

    Description Consider a positive integer X,and let S be the sum of all positive integer divisors of 2 ...

随机推荐

  1. python内建模块Collections

    # -*- coding:utf-8 -*- # OrderedDict可以实现一个FIFO(先进先出)的dict, # 当容量超出限制时,先删除最早添加的Key: from collections ...

  2. [Clr via C#读书笔记]Cp2生成打包部署和管理应用程序和类型

    Cp2生成打包部署和管理应用程序和类型 部署问题 DLL Hell;安装的复杂性:安全性:代码访问安全性. csc.exe的简单使用. 元数据 定义表:引用表:清单表: 程序集 重用,版本控制,安全的 ...

  3. HTMLTestRunner带饼图

    # -*- coding: utf-8 -*- """ A TestRunner for use with the Python unit testing framewo ...

  4. HDU 3264/POJ 3831 Open-air shopping malls(计算几何+二分)(2009 Asia Ningbo Regional)

    Description The city of M is a famous shopping city and its open-air shopping malls are extremely at ...

  5. Windows Phone编程回顾

    前言 已有一年多没有碰WP相关的开发了. 近期经常看博客园的文章, 发现开发WP应用的同学很多, 其中博问频道关于"WPF", "C#", "WP8& ...

  6. 事后分析报告(M2阶段)

    我们的项目是自选项目,一款名为备忘录锁屏MemoryDebris的软件. 在第二轮的迭代中,由于各科的大作业都集中在这一段时间,所以这段时间各个组员间的负担都比较大,但是在大家共同努力,最终我们还是交 ...

  7. TCP系列25—重传—15、DSACK虚假重传探测

    一.DSACK介绍 RFC2883通过指定使用SACK来指示接收端的重复包(duplicate packet)扩展了RFC2018对SACK选项的定义(SACK选项的介绍和示例参考前面内容).RFC2 ...

  8. bootstrap控件点击之后没有反应的原因

    引用的jquery.js文件要放到bootstrap.js的前面 jquery.js文件版本太低. 这些问题可以通过firebug或者谷歌调试器发现. 问题很简单,简单记录下,以免以后遗忘.

  9. HDU 2117 Just a Numble

    http://acm.hdu.edu.cn/showproblem.php?pid=2117 Problem Description Now give you two integers n m, yo ...

  10. VUE01指令

    一.下载Vue2.0的两个版本: 官方网站:http://vuejs.org/ 开发版本:包含完整的警告和调试模式 生产版本:删除了警告,进行了压缩 二.项目结构搭建 这个部分要视频中有详细讲解. 三 ...