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. 清橙 A1318 加强版:Almost

    题意: 直接看题面吧 原版:\(n \leq 1e5, q \leq 3e4, TL 5s, ML 256G\) 加强版1:\(n,q \leq 1.5e5, TL 5s, ML 256G\) 加强版 ...

  2. parity 注记词

    spousal tint untold around rosy daintily unrated sheep choice showpiece chirping gala

  3. Python3 数值类型与运算符

    1.数值类型与进制 (1)基本类型 整型:int 浮点型:float 布尔类型:bool 复数:complex print(type(1)) print(type(1.1)) print(type(F ...

  4. SPOJ 694 Distinct Substrings/SPOJ 705 New Distinct Substrings(后缀数组)

    Given a string, we need to find the total number of its distinct substrings. Input T- number of test ...

  5. Python字符串格式化表达式和格式化方法

    Python格式化字符串由两种方式可以选择:一种是格式化表达式(Formatting Expression),一种是格式化方法(Formatting Method).其中格式化表达式在全Python版 ...

  6. 互评Alpha版本——Thunder团队

    基于NABCD评论作品 Hello World! :http://www.cnblogs.com/120626fj/p/7807544.html 欢迎来怼 :http://www.cnblogs.co ...

  7. 【转】自定义(滑动条)input[type="range"]样式

    1.如何使用滑动条? 用法很简单,如下所示: <input type="range" value="0"> 各浏览器原始样式如下: Chrome:  ...

  8. Debian以及Ubuntu源设置

    在使用Debian和Ubuntu时,经常为了软件源烦恼,最近发现了一个网页,可以根据国家来设置源的地址,效果还不错. Debian:http://debgen.simplylinux.ch/ Ubun ...

  9. 【alpha】Scrum站立会议第1次····10.16

    小组名称:nice! 小组成员:李权 于淼 杨柳 刘芳芳 项目内容:约跑app 1.任务进度 成员 已完成 当日要完成 李权 搭建好Android Studio环境 数据库设计 于淼 搭建好Andro ...

  10. binlog2sql数据恢复

    牛叉的工具有好几个,包括MyFlash.binlog2Sql.mysqlbinlog_flashback,还有一些收费的等等,各有优劣,具体使用可自行百度 1.安装binlog2sql shell&g ...