求Ax+By<=C,非负整数对(x,y)的个数

首先令y=0;则x<=(C/A);ans=(C/A)+1;

将Ax+By=C反转之后利用类欧几里得算法:f(a,b,c,n)=∑((a*i+b)/c) (0<=i<=n);求解

反转之后,a=A,b=C%A,c=b,n=C/A;

#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define bug printf("bug\n");
#define N 1000005
#define pb emplace_back
#define fi first
#define se second
#define sc scanf
#define pf printf
#define Endl '\n'
using namespace std;
const ll inf=1e18;
const ll mod=;
ll qm(ll a,ll b){
ll ans=;
while(b){
if(b&)ans=ans*a%mod;
a=a*a%mod;b>>=;
}
return (ans%mod+mod)%mod;
}
ll cal(ll a,ll b,ll c,ll n){
if(a==)return (b/c)*(n+);
if(a>=c||b>=c)return cal(a%c,b%c,c,n)+n*(n+)*(a/c)/+(b/c)*(n+);
ll m=(a*n+b)/c;
return n*m-cal(c,c-b-,a,m-);
}
int main()
{ ios::sync_with_stdio(false);cin.tie();cout.tie();
ll a,b,c;
cin>>a>>b>>c;
cout<<cal(a,c%a,b,c/a)+c/a+<<endl; return ;
}

Gym100920J的更多相关文章

随机推荐

  1. CRM系统新思维

    客户关系管理系统(CRM系统)是管理公司当前以及未来潜在客户的系统,其主要目的是通过优化客户关系实现公司销售业绩的长期增长,它是企业信息系统的核心之一.目前,移动互联网.大数据以及人工智能技术发展日新 ...

  2. Android内核漏洞利用技术实战:环境搭建&栈溢出实战

    前言 Android的内核采用的是 Linux 内核,所以在Android内核中进行漏洞利用其实和在 一般的 x86平台下的 linux 内核中进行利用差不多.主要区别在于 Android 下使用的是 ...

  3. pycharm安装激活及简单设置

    (1)在激活界面的License server输入:http://idea.liyang.io/:或者:点击help→Register→License sever ,输入http://idea.liy ...

  4. Ionic step by step (1)

    刚接触 ionic,一步一步学习,有错误的,望大家指出. 公式 Ionic = Cordova + Angular2 + ionic CSS Cordova: 提供了使用 JavaScript 调用 ...

  5. 【转】数据分析与处理之二(Leveldb 实现原理)

    郑重声明:本篇博客是自己学习 Leveldb 实现原理时参考了郎格科技系列博客整理的,原文地址:http://www.samecity.com/blog/Index.asp?SortID=12,只是为 ...

  6. Oracle ALL DBA表

    select * from all_tab_comments -- 查询所有用户的表,视图等 select * from user_tab_comments -- 查询本用户的表,视图等 select ...

  7. cent7中kickstart

    一.基本环境 操作系统:CentOS7.4 内核版本:3.10.0-862.11.6.el7.x86_64 二.组件部署 yum安装tftp tftpd-server xinetd http dhcp ...

  8. Invalid argument during startup: unknown conf file parameter : requirepass

    redis 设置来密码,出现来这个错误, 把配置文件那一行的 空格 去掉 # requirepass foobared 改成 requirepass 123456 因为# 和 requirepass ...

  9. [翻译] SAMCoreImageView

    SAMCoreImageView https://github.com/soffes/SAMCoreImageView Render a CIImage in an OpenGL thingy so ...

  10. Custom Settings.in 配置信息收集

    [Settings] Priority=Default Properties=MyCustomProperty [Default] ;是否允许部署操作系统到目标计算机 OSInstall=YES ;是 ...