码迷,mamicode.com
首页 > 其他好文 > 详细

今日SGU 5.16

时间:2018-05-16 23:54:16      阅读:184      评论:0      收藏:0      [点我收藏+]

标签:one   +=   lse   src   gcd   sync   splay   lcm   --   

SGU 119

题意:给你N、A0、B0,然后问所有X、Y,若A0X+B0Y能被N整除,则AX+BY也能被N整除,求所有的A、B.(0<=A、B<N)

收获:枚举

因为a0x+b0y=k1n,ax+by=k2n,所以,ax+by=k2/k1(a0x+b0y),所以我们枚举k(0~n-1),然后去重就行

技术分享图片
#include<bits/stdc++.h>
#define de(x) cout<<#x<<"="<<x<<endl;
#define dd(x) cout<<#x<<"="<<x<<" ";
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define repd(i,a,b) for(int i=a;i>=(b);--i)
#define repp(i,a,b,t) for(int i=a;i<(b);i+=t)
#define ll long long
#define mt(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
#define pii pair<int,int>
#define pdd pair<double,double>
#define pdi pair<double,int>
#define mp(u,v) make_pair(u,v)
#define sz(a) (int)a.size()
#define ull unsigned long long
#define ll long long
#define pb push_back
#define PI acos(-1.0)
#define qc std::ios::sync_with_stdio(false)
#define db double
#define all(a) a.begin(),a.end()
const int mod = 1e9+7;
const int maxn = 1e5+5;
const double eps = 1e-6;
using namespace std;
bool eq(const db &a, const db &b) { return fabs(a - b) < eps; }
bool ls(const db &a, const db &b) { return a + eps < b; }
bool le(const db &a, const db &b) { return eq(a, b) || ls(a, b); }
ll gcd(ll a,ll b) { return a==0?b:gcd(b%a,a); };
ll lcm(ll a,ll b) { return a/gcd(a,b)*b; }
ll kpow(ll a,ll b) {ll res=1;a%=mod; if(b<0) return 1; for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll read(){
    ll x=0,f=1;char ch=getchar();
    while (ch<0||ch>9){if(ch==-)f=-1;ch=getchar();}
    while (ch>=0&&ch<=9){x=x*10+ch-0;ch=getchar();}
    return x*f;
}
//inv[1]=1;
//for(int i=2;i<=n;i++) inv[i]=(mod-mod/i)*inv[mod%i]%mod;
pii ans[maxn];
int main(){
    int n,a0,b0;
    cin>>n>>a0>>b0;
    rep(i,0,n) ans[i]=mp(i*a0%n,i*b0%n);
    sort(ans,ans+n);
    n = unique(ans,ans+n) - ans;
    printf("%d\n",n);
    rep(i,0,n) printf("%d %d\n",ans[i].fi,ans[i].se);
    return 0;
}
View Code

 

今日SGU 5.16

标签:one   +=   lse   src   gcd   sync   splay   lcm   --   

原文地址:https://www.cnblogs.com/chinacwj/p/9048764.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!