HDU3524 数论
Perfect Squares
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 582 Accepted Submission(s): 323
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.
Then it follows T lines, each line is a positive number n(0<n<2*10^9).
/*
就是打表+找规律
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 数论的更多相关文章
- Codeforces Round #382 Div. 2【数论】
C. Tennis Championship(递推,斐波那契) 题意:n个人比赛,淘汰制,要求进行比赛双方的胜场数之差小于等于1.问冠军最多能打多少场比赛.题解:因为n太大,感觉是个构造.写写小数据, ...
- NOIP2014 uoj20解方程 数论(同余)
又是数论题 Q&A Q:你TM做数论上瘾了吗 A:没办法我数论太差了,得多练(shui)啊 题意 题目描述 已知多项式方程: a0+a1x+a2x^2+..+anx^n=0 求这个方程在[1, ...
- 数论学习笔记之解线性方程 a*x + b*y = gcd(a,b)
~>>_<<~ 咳咳!!!今天写此笔记,以防他日老年痴呆后不会解方程了!!! Begin ! ~1~, 首先呢,就看到了一个 gcd(a,b),这是什么鬼玩意呢?什么鬼玩意并不 ...
- hdu 1299 Diophantus of Alexandria (数论)
Diophantus of Alexandria Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java ...
- 【BZOJ-4522】密钥破解 数论 + 模拟 ( Pollard_Rho分解 + Exgcd求逆元 + 快速幂 + 快速乘)
4522: [Cqoi2016]密钥破解 Time Limit: 10 Sec Memory Limit: 512 MBSubmit: 290 Solved: 148[Submit][Status ...
- bzoj2219: 数论之神
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #i ...
- hdu5072 Coprime (2014鞍山区域赛C题)(数论)
http://acm.hdu.edu.cn/showproblem.php?pid=5072 题意:给出N个数,求有多少个三元组,满足三个数全部两两互质或全部两两不互质. 题解: http://dty ...
- ACM: POJ 1061 青蛙的约会 -数论专题-扩展欧几里德
POJ 1061 青蛙的约会 Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%lld & %llu Descr ...
- 数论初步(费马小定理) - Happy 2004
Description Consider a positive integer X,and let S be the sum of all positive integer divisors of 2 ...
随机推荐
- 《Effective C++》读书笔记 条款02 尽量以const,enum,inline替换#define
Effective C++在此条款中总结出两个结论 1.对于单纯常量,最好以const对象或enum替换#define 2.对于形似函数的宏,最好改用inline函数替换#define 接下来我们进行 ...
- 某即时通信工具与RMS结合
某客户内部使用及时通信工具与RMS相结合,如果客户使用了海外版Office 365E3可以直接在手机端使用Office app打开. 如果客户没有使用海外版Office 365E3的版本,需要结合本地 ...
- 深度学习笔记 (一) 卷积神经网络基础 (Foundation of Convolutional Neural Networks)
一.卷积 卷积神经网络(Convolutional Neural Networks)是一种在空间上共享参数的神经网络.使用数层卷积,而不是数层的矩阵相乘.在图像的处理过程中,每一张图片都可以看成一张“ ...
- Reject Inference: Your Data is Deceiving You
Keyword: Reject Inference Suppose there is a dataset of several attributes, including working condit ...
- js经典试题之原型与继承
js经典试题之原型与继承 1:以下代码中hasOwnProperty的作用是? var obj={} …….. obj.hasOwnProperty("val") 答案:判断obj ...
- 软工第三次作业——个人PSP
9.22--9.26本周例行报告 1.PSP(personal software process )个人软件过程. 类型 任务 预计时间 开始时间 结束时间 中断时间 实际用时 准备工作 学习重定向 ...
- 软件工程第二周PSP
- Internet History,Tecchnology and Security
Internet History Internet Technologe Internet Secure
- 一个例子说明mouseover事件与mouseenter事件的区别
<html> <head> <meta charset="UTF-8"> <title>haha</title> < ...
- Windows 7中安装Solr7
最新忙里偷闲,研究一下了Lucene.Net,发现操作比较繁琐,同比相似的功能,感觉Solr比较简单,容易使用.不过由于Solr使用的是Java的环境,对于.Net开发的人员来说,还是比较陌生,搭配环 ...