Law of Commutation HDU
来源:互联网 发布:c语言中用户标识符 编辑:程序博客网 时间:2024/06/06 03:54
Law of Commutation HDU - 6189
As we all know, operation ''+'' complies with the commutative law. That is, if we arbitrarily select two integers
There are no more than
Input
Each test case contains two positive integers
For all test cases, you can assume that
Output
For each test case, output an integer denoting the number of
Sample Input
2 3
2 2
Sample Output
1
2
题意: 略。
思路: 打表+ 不放弃找规律+ 稍微有点数学意识。
比赛的时候打了个表,现在看了好像打表的时候就打错了,不过还是接着找了一下规律:
a 为奇数的时候 只有 1 ,对于偶数情况,打表发现 b —> n 的情况 比较混乱,似乎没有规律,就 放弃了......
(大概这就是蒻~吧)
正解: 对于偶数情况 (a,b都为偶数) b<n 的情况比较混乱,直接暴力枚举, b>=n 的时候就可以有公式可循了。
其实仔细想想也是这样,即 考虑 a^b 大概只有 a^b % 2^n == 0 的时候才有解,要保证 a^b 存在 2^n 即 b>n ,
其实是瞎解释的,可以忽略。
那么b>= n 的时候:~~~~ 点击打开链接
#pragma comment(linker, "/STACK:1024000000,1024000000")//#include <bits/stdc++.h>#include<string>#include<cstdio>#include<cstring>#include<cmath>#include<iostream>#include<queue>#include<stack>#include<vector>#include<set>#include<algorithm>#define maxn 10010#define INF 0x3f3f3f3f#define eps 1e-8#define MOD 1000000007#define ll long longusing namespace std;ll Pow(ll a,ll b,ll mod){ ll ans=1; a=a%mod; while(b) { if(b&1) ans=ans*a%mod; b>>=1; a=a*a%mod; } return ans%mod;}ll Pow1(ll a,ll b){ ll ans=1; while(b) { if(b&1) ans*=a; b>>=1; a=a*a; } return ans;}int main(){ ll n,a; while(scanf("%lld%lld",&n,&a)!=EOF) { if(a&1) { puts("1"); continue; } ll mod=Pow1(2,n); ll t=Pow1(2,(n-1)/a+1); ll z=mod/t-(n-1)/t; ll ans=0; for(int i=1;i<n;i++) { if(Pow(a,i,mod)==Pow(i,a,mod)) ans++; } ans+=z; cout<<ans<<endl; } return 0;}
- Law of Commutation HDU
- HDU 6189 Law of Commutation 2017ACM-ICPC 广西邀请赛 (打表找规律)
- 解题报告:HDU_6189 Law of Commutation (找规律)
- hdu6189 Law of Commutation 2017ACM-ICPC全国邀请赛(广西) 找规律
- law of demeter
- law of attraction
- The law of Demeter
- The Law of Refraction
- 迪米特法则(Law of Demeter)
- The Law of Leaky Abstractions
- 迪米特法则 Law of Demeter
- law
- 迪米特法则 (Law of Demeter, LoD)
- 迪米特法则(Law of Demeter)
- 反射规则 the law of reflection
- 迪米特法则(Law of Demeter)
- 得墨忒耳定律(Law of Demeter)
- 迪米特法则(Law of Demeter) 简介
- 邝斌的ACM模板(Baby-Step Giant-Step)
- HighCharts常见使用问题总结(个人笔记)
- 基于SurfaceTexture的静默/无预览拍照方案
- 二叉树
- C++ std::vector指定位置插入
- Law of Commutation HDU
- 视频播放问题总结
- mysql索引优缺点以及创建的时机
- WOJ1187-Difference Minimizing
- kshon学习笔记之android相对布局
- 美团前端一面
- 邝斌的ACM模板(自适应 simpson 积分)
- 习题 6.12 有一行电文,已按下面规律译成密码:A-Z a-z即第一个字母变成第26个字母,第i个字母变成第(26-i+1)个字母。非字母字符不变。要求编程序将密码译回原文,并输出密码和原文。
- 湖南省2017省赛A题