. Number throry
steve 学完了快速幂,现在会他快速的计算:(ij)%d , Alex 作为一个数学大师,给了 steve 一个问题:已知
i∈[1,n],j∈[1,m] ,计算满足 (ij)%d=0 的 (i,j) 的对数。
输入格式
T组输入,对于每一组输入三个数n,m,d。
(1≤T≤1000,1≤n,m,d≤109)。
输出格式
对于每组输入,输出答案,每个答案占一行。
样例
4
3 10 7
3 5 3
10 30 6
100 100 8
0
5
30
4937
不太懂,,先记下来再说
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll qpow(ll a,ll b){
ll ans=;
while(b){
if(b&) ans=(ans*a);
a=(a*a);
b>>=;
}
return ans;
}
int main(){
int T;scanf("%d",&T);
while(T--){
ll n,m,d;
scanf("%lld %lld %lld",&n,&m,&d);
vector<pair<ll,ll> > prs;
vector<pair<ll,ll> >::iterator it;
for(ll i=;i*i<=d;i++){
if(d%i==){
long long cnt=;
while(d%i==){
d/=i;cnt++;
}
prs.push_back({i,cnt});
}
}
ll res=;
if(d!=) prs.push_back({d,});
for(ll j=;j<=min(m,1LL*);j++){
ll g=;
// for(auto v:prs)
for(it=prs.begin();it!=prs.end();it++)
{
g*=qpow( it->first,( it->second+j-)/j);
}
if(j==) res+=(m-)*(n/g);
else res+=n/g;
}
printf("%lld\n",res);
}
return ;
}
. Number throry的更多相关文章
- JavaScript Math和Number对象
目录 1. Math 对象:数学对象,提供对数据的数学计算.如:获取绝对值.向上取整等.无构造函数,无法被初始化,只提供静态属性和方法. 2. Number 对象 :Js中提供数字的对象.包含整数.浮 ...
- Harmonic Number(调和级数+欧拉常数)
题意:求f(n)=1/1+1/2+1/3+1/4-1/n (1 ≤ n ≤ 108).,精确到10-8 (原题在文末) 知识点: 调和级数(即f(n))至今没有一个完全正确的公式, ...
- Java 特定规则排序-LeetCode 179 Largest Number
Given a list of non negative integers, arrange them such that they form the largest number. For exam ...
- Eclipse "Unable to install breakpoint due to missing line number attributes..."
Eclipse 无法找到 该 断点,原因是编译时,字节码改变了,导致eclipse无法读取对应的行了 1.ANT编译的class Eclipse不认,因为eclipse也会编译class.怎么让它们统 ...
- 移除HTML5 input在type="number"时的上下小箭头
/*移除HTML5 input在type="number"时的上下小箭头*/ input::-webkit-outer-spin-button, input::-webkit-in ...
- iOS---The maximum number of apps for free development profiles has been reached.
真机调试免费App ID出现的问题The maximum number of apps for free development profiles has been reached.免费应用程序调试最 ...
- 有理数的稠密性(The rational points are dense on the number axis.)
每一个实数都能用有理数去逼近到任意精确的程度,这就是有理数的稠密性.The rational points are dense on the number axis.
- [LeetCode] Minimum Number of Arrows to Burst Balloons 最少数量的箭引爆气球
There are a number of spherical balloons spread in two-dimensional space. For each balloon, provided ...
- [LeetCode] Number of Boomerangs 回旋镖的数量
Given n points in the plane that are all pairwise distinct, a "boomerang" is a tuple of po ...
随机推荐
- Mysql常用sql语句(一)- 操作数据库
21篇测试必备的Mysql常用sql语句,每天敲一篇,每次敲三遍,每月一循环,全都可记住!! https://www.cnblogs.com/poloyy/category/1683347.html ...
- [set]Codeforces 830B-Cards Sorting
Cards Sorting time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- vue采坑记录
1.项目在浏览器运行的时候没有ico图标 <link rel="shortcut icon" type="image/x-icon" href=" ...
- 强化学习之一:从TensorFlow开始(Start from TensorFlow)
本文是对Tensorflow官方教程的个人(tomqianmaple@outlook.com)中文翻译,供大家学习参考. 官方教程链接 tf的扬帆起航Getting Started With Tens ...
- 10行Python代码实现目标检测
要知道图像中的目标是什么? 或者你想数一幅图里有多少个苹果? 在本文中,我将向你展示如何使用Python在不到10行代码中创建自己的目标检测程序. 如果尚未安装python库,你需要安装以下pytho ...
- Github标星过万,Python新手100天学习计划,这次再学不会算我输!
作为目前最火也是最实用的编程语言,Python不仅是新手入门程序界的首选,也逐渐成为了从大厂到小厂,招牌需求list的必要一条. 当然,学Python这件事情,你可能也和文摘菌一样,已经下了一百次 ...
- CentOS 6.5 nginx+tomcat+ssl配置
本文档用于指导在CentOS 6.5下使用nginx反向代理tomcat,并在nginx端支持ssl. 安装nginx.参见CentOS 6 nginx安装. SSL证书申请.参见腾讯SSL证书申请和 ...
- STM32CubeMX的使用
1.STM32CubeMX简介 STM32CubeMx软件是ST公司为STM32系列单片机快速建立工程,并快速初始化使用到的外设.GPIO等,大大缩短了我们的开发时间.同时,软件不仅能配置STM32外 ...
- 为什么要用内插字符串代替string.format
知道为什么要用内插字符串,只有踩过坑的人才能明白,如果你曾今使用string.format超5个以上占位符,那其中的痛苦我想你肯定是能够共鸣的. 一:痛苦经历 先上一段曾今写过的一段代码,大家来体会一 ...
- 1065 A+B and C (64bit) (20分)(水)
Given three integers A, B and C in [−], you are supposed to tell whether A+B>C. Input Specificati ...