G36 生成函数的应用

视频链接:https://www.bilibili.com/video/BV1fP411g7bm/

UOJ #3028. 食物

复制代码
#include<bits/stdc++.h>
using namespace std;

const int P=10007;
char s[510];

int main(){
  scanf("%s",s);
  int n=0,len=strlen(s);
  for(int i=0;i<len;i++)
    n=(n*10%P+s[i]-'0')%P;
  int ans=n*(n+1)%P*(n+2)%P*1668%P;
  printf("%d\n",ans);
  return 0;
}
复制代码
复制代码
#include<bits/stdc++.h>
using namespace std;

const int P=10007;
char s[510];

int qpow(int a,int b){
  int res=1;
  while(b){
    if(b&1) res=(res*a)%P;
    a=(a*a)%P;        
    b>>=1;
  } 
  return res;
}
int main(){
  scanf("%s",s);
  int n=0,len=strlen(s);
  for(int i=0;i<len;i++)
    n=(n*10%P+s[i]-'0')%P;
  int ans=n*(n+1)%P*(n+2)%P*qpow(6,P-2)%P;
  printf("%d\n",ans);
  return 0;
}
复制代码

 POJ 3734 Blocks

复制代码
#include <cstdio>
using namespace std;

const int P=10007;
int qpow(int a, int b){
  int res=1;
  while(b){
    if(b & 1) res=res*a%P;
    a=a*a%P;
    b>>=1;
  }
  return res;
}
int main(){
  int t,n,ans;
  scanf("%d", &t);
  while(t--){
    scanf("%d", &n);
    ans=(qpow(4,n-1)+qpow(2,n-1))%P;
    printf("%d\n", ans);
  }
  return 0;
}
复制代码

 

posted @   董晓  阅读(316)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
点击右上角即可分享
微信分享提示