#10193. 「一本通 6.1 例 1」序列的第 k 个数
裸的等差数列,等比数列
附上公式:等差数列 (其中为公差,为第几项的项数)
等比数列 (其中为公比,为第几项的项数)
还要注意一些取模的问题。做这道题不用想太多,直接做就好了,等比数列都是整除的,不然取模咋个办
应试总结:能开 的就不要舍不得开,更保险,乘法取模有待进一步深入,不要乱取
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
const int mod = 200907 ;
inline int wread(){
char c=getchar ();int flag=1,wans=0;
while (c<'0'||c>'9'){if (c=='-') flag=-1;c=getchar ();}
while (c>='0'&&c<='9'){wans=wans*10+c-'0';c=getchar ();}
return wans*=flag;
}
int T;
int a,b,c,k;
int fast_cal (int x,int y){
int ans=1;
while (y){
if (y&1) ans=((long long)(ans%mod)*(long long)(x%mod))%mod;
x=((long long)(x%mod)*(long long)(x%mod))%mod,y>>=1;
}
return ans%mod;
}
int main (){
T=wread();
while (T--){
a=wread(),b=wread(),c=wread(),k=wread();
if (a+c==(b<<1)){//等差
int d=b-a;
int pr= ( a % mod + ( (long long)(k-1) * (long long)d ) % mod ) %mod ;
printf("%d\n",pr);
}
else {//等比
int q=b/a;
int pr=((a%mod)*(fast_cal(q,k-1)%mod))%mod;
printf("%d\n",pr%mod);
}
}
return 0;
}
#10194. 「一本通 6.1 练习 1」A 的 B 次方
模板题
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#define LL long long
using namespace std;
inline LL ll_wread(){
char c=getchar ();LL flag=1,wans=0;
while (c<'0'||c>'9'){if (c=='-') flag=-1;c=getchar ();}
while (c>='0'&&c<='9'){wans=wans*10+c-'0';c=getchar ();}
return wans*=flag;
}
LL fast_cal (LL a,LL b,LL mod){
LL ans=1;
while (b){
if (b&1) ans=((ans%mod)*(a%mod))%mod;
a=((a%mod)*(a%mod))%mod;b>>=1;
}
return ans%mod;
}
int main (){
LL a=ll_wread() ,b=ll_wread(),mod=ll_wread();
printf("%lld\n",fast_cal(a,b,mod));
return 0;
}
#10195. 「一本通 6.1 练习 2」转圈游戏
#10196. 「一本通 6.1 练习 3」越狱
正难则反::
显然可以用表示所有的方案数,即个相乘
再表示出不相邻的方案数:
原理:第一个人可以任意取一个宗教,第二个人可以取 个宗教,第三个人也可以取 个宗教(只需要和第二个人的宗教不同即可)
我觉得这道题哪里像模板了!!!好吧,我太菜了
总结最重要:
正难则反,用好这个思想!!!一定要记住:拓展思维
//-> m^n-m*(m-1)^(n-1)
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#define LL long long
using namespace std;
const LL mod = 100003;
inline LL wread(){
char c=getchar ();LL flag=1,wans=0;
while (c<'0'||c>'9'){if (c=='-') flag=-1;c=getchar ();}
while (c>='0'&&c<='9'){wans=wans*10+c-'0';c=getchar ();}
return wans*=flag;
}
LL m,n;
LL fast_cal (LL a,LL b){
LL ans=1;
while (b){
if (b&1) ans=(ans%mod*a%mod)%mod;
a=(a%mod*a%mod)%mod;b>>=1;
}
return ans;
}
int main (){
m=wread();n=wread();
printf ("%lld\n",((fast_cal(m,n)%mod-m%mod*fast_cal(m-1,n-1)%mod)+mod)%mod);
return 0;
}