Arab Collegiate Programming Contest 2012 J- Math Homework
思路:由于只有1-6这几个数,而这几个数的最小公倍数是60,所以只需要求出60以内有多少满足条件的数即可。
再就是求出对于给定的n,求出60的倍数。然后就是怎样求的问题了。
首先可以写成如下形式:
10n-40=60*n (把最后的40个数去掉,最后在求结果的时候再加上)
n=(10n-40)/60. (结果一定可以整除)
代码如下:
#include<cstdio>
#define ll long long
#define mod 1000000007
ll pw(ll a,ll b)
{
ll ans=;
while(b){
if(b&) ans=ans*a%mod;
b>>=;
a=a*a%mod;
}
return ans;
}
int main()
{
int i,j,t;
ll n;
char str[];
bool f[];
scanf("%d",&t);
while(t--){
scanf("%I64d %s",&n,str);
for(i=;i<;i++){
f[i]=;
for(j=;j<;j++){
if(str[j]==''&&i%(j+)==) f[i]=;
else if(str[j]==''&&i%(j+)!=) f[i]=;
}
}
int c=;
if(n==){
for(i=;i<=;i++) c+=f[i];
printf("%d\n",c);
continue;
}
for(i=;i<;i++) c+=f[i];
ll p=pw(,n);
ll ans=(p-+mod)%mod*pw(,mod-)%mod;
ans=ans*c%mod;
for(i=;i<;i++) ans+=f[i];
printf("%I64d\n",ans);
}
return ;
}
Arab Collegiate Programming Contest 2012 J- Math Homework的更多相关文章
- 2018 Arab Collegiate Programming Contest (ACPC 2018) E - Exciting Menus AC自动机
E - Exciting Menus 建个AC自动机求个fail指针就好啦. #include<bits/stdc++.h> #define LL long long #define fi ...
- 2018 Arab Collegiate Programming Contest (ACPC 2018) G. Greatest Chicken Dish (线段树+GCD)
题目链接:https://codeforces.com/gym/101991/problem/G 题意:给出 n 个数,q 次询问区间[ li,ri ]之间有多少个 GCD = di 的连续子区间. ...
- 2018 Arab Collegiate Programming Contest (ACPC 2018) H - Hawawshi Decryption 数学 + BSGS
H - Hawawshi Decryption 对于一个给定的生成数列 R[ 0 ] 已知, (R[ i - 1 ] * a + b) % p = R[ i ] (p 是 质数), 求最小的 x 使得 ...
- Gym 100952E&&2015 HIAST Collegiate Programming Contest E. Arrange Teams【DFS+剪枝】
E. Arrange Teams time limit per test:2 seconds memory limit per test:64 megabytes input:standard inp ...
- The Ninth Hunan Collegiate Programming Contest (2013) Problem J
Problem J Joking with Fermat's Last Theorem Fermat's Last Theorem: no three positive integers a, b, ...
- zoj The 12th Zhejiang Provincial Collegiate Programming Contest Capture the Flag
http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5503 The 12th Zhejiang Provincial ...
- zoj The 12th Zhejiang Provincial Collegiate Programming Contest Team Formation
http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5494 The 12th Zhejiang Provincial ...
- zoj The 12th Zhejiang Provincial Collegiate Programming Contest Lunch Time
http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5499 The 12th Zhejiang Provincial ...
- zoj The 12th Zhejiang Provincial Collegiate Programming Contest Convert QWERTY to Dvorak
http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5502 The 12th Zhejiang Provincial ...
随机推荐
- 2017ACM暑期多校联合训练 - Team 5 1001 HDU 6085 Rikka with Candies (模拟)
题目链接 Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, s ...
- php查询mysql返回大量数据结果集导致内存溢出的解决方法
web开发中如果遇到php查询mysql返回大量数据导致内存溢出.或者内存不够用的情况那就需要看下MySQL C API的关联,那么究竟是什么导致php查询mysql返回大量数据时内存不够用情况? 答 ...
- Tomcat 调优及 JVM 参数优化
Tomcat 本身与 JVM 优化 Tomcat:调整Server.xml JVM:bat启动服务方式的话修改catalina.bat 服务式启动的话参考:http://www.cnblogs.com ...
- Mysql储存过程3:if语句
--if/else语句 if 条件 then SQL语句 else SQL语句elseifSQL语句 end if; create procedure test1( number int ) begi ...
- http状态码说明
在学习网页设计的时候都应该知道状态码,但我们常见的状态码都是200,404,下面介绍其他的状态值 1开头的http状态码表示临时响应并需要请求者继续执行操作的状态代码. 100 (继续) 请求者应 ...
- Linux自身安全SElinux
查看SELinux状态: 1./usr/sbin/sestatus -v ##如果SELinux status参数为enabled即为开启状态 SELinux status: ...
- 小程序授权怎么写 , 用户点击取消授权 调用 wx.authorize
点击获取授权 onLoad: function (options) { console.log("onLoad====="); var that=this; wx.getUserI ...
- MINIBASE源代码阅读笔记之buffer manager
BufDesc frame 们的 descriptor(见BufHashTbl注释),包括 pageNo: 这个 frame 在文件里的id,page number prevframe: -1 表示此 ...
- CoreOS中随着系统启动Docker Container
Start containers automatically https://docs.docker.com/engine/admin/host_integration/ https://www.fr ...
- Redis实战(六)
查询数据 1.使用Linq匹配关键字查询 using (var redisClient = RedisManager.GetClient()) { var user = redisClient.Get ...