思路:由于只有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的更多相关文章

  1. 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 ...

  2. 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 的连续子区间. ...

  3. 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 使得 ...

  4. 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 ...

  5. 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, ...

  6. 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 ...

  7. zoj The 12th Zhejiang Provincial Collegiate Programming Contest Team Formation

    http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5494 The 12th Zhejiang Provincial ...

  8. zoj The 12th Zhejiang Provincial Collegiate Programming Contest Lunch Time

    http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5499 The 12th Zhejiang Provincial ...

  9. 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 ...

随机推荐

  1. 【leetcode 简单】第四十题 求众数

    给定一个大小为 n 的数组,找到其中的众数.众数是指在数组中出现次数大于 ⌊ n/2 ⌋ 的元素. 你可以假设数组是非空的,并且给定的数组总是存在众数. 示例 1: 输入: [3,2,3] 输出: 3 ...

  2. 【leetcode 简单】第十七题 x 的平方根

    实现 int sqrt(int x) 函数. 计算并返回 x 的平方根,其中 x 是非负整数. 由于返回类型是整数,结果只保留整数的部分,小数部分将被舍去. 示例 1: 输入: 4 输出: 2 示例 ...

  3. 2017ACM暑期多校联合训练 - Team 3 1003 HDU 6058 Kanade's sum (模拟)

    题目链接 Problem Description Give you an array A[1..n]of length n. Let f(l,r,k) be the k-th largest elem ...

  4. 可怕的npm蠕虫

    https://hackernoon.com/im-harvesting-credit-card-numbers-and-passwords-from-your-site-here-s-how-9a8 ...

  5. 当while read line 遇到 ssh

    问题:while read line 中使用ssh只能读取一行? #!/bin/sh while read line do echo $line ssh root@$line "echo 1 ...

  6. 用PHP去实现数据库查询结果缓存

    有些时候我们希望减少对数据库的查询来提高程序的性能,因为这些数据不是经常变更的,而是会在很长一段时间内都不会变化,因此,我们每连接一次数据库,都会把相应的结果用文件的形式保存起来.比如对于一个商城来说 ...

  7. geoip 扩展包根据ip定位详情

    教程:https://laravel-china.org/courses/laravel-package/2024/get-the-corresponding-geo-location-informa ...

  8. 版本控制软件——tortoiseSVN的基础使用

    零 基本功能介绍... 2 一 安装及下载client端... 2 二 登陆和文件下载... 2 三 新增档案及目录到服务器中... 4 四 文件对比... 13 4.1 文件回溯... 13 4.2 ...

  9. POJ 3253 Fence Repair(哈夫曼编码)

    题目链接:http://poj.org/problem?id=3253 题目大意: 有一个农夫要把一个木板钜成几块给定长度的小木板,每次锯都要收取一定费用,这个费用就是当前锯的这个木版的长度 给定各个 ...

  10. poj 2420(模拟退火)

    A Star not a Tree? Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6066   Accepted: 285 ...