SGU 119

欧几里得- -要分N种情况- -

#include<cstdio>
#include<algorithm>
using namespace std;
int gcd(int x,int y){if (y==0) return x;return gcd(y,x%y);}
struct node
{
    int x,y;
        friend bool operator < (const node &a, const node &b)
        {
            if(a.x != b.x) return a.x < b.x;
            return a.y < b.y;
        }
}ans[10030];
int main()
{
    int n,a1,b1;
    scanf("%d%d%d",&n,&a1,&b1);
    a1=a1%n;b1=b1%n;
    int i=n/gcd(n,a1),j=n/gcd(n,b1);
    int sum=i*j/gcd(i,j);
    for (int i=1;i<=sum;i++)
    {
        ans[i].x=(a1*i)%n;
        ans[i].y=(b1*i)%n;
    }
    sort(ans+1,ans+1+sum);
    printf("%d\n",sum);
    for (int i=1;i<=sum;i++) printf("%d %d\n",ans[i].x,ans[i].y);
    return 0;
}

SGU 119

时间: 2024-08-28 09:43:43

SGU 119的相关文章

SGU 119 Beautiful People

#include <cstdio> #include <cstring> #include <algorithm> using namespace std; #define maxx 100050 struct node { int a,b,id; }g[maxx]; int root[maxx]; int id[maxx]; int len; void output(int x) { if(x==-1)return; output(root[x]); printf(&

Magic Pairs - SGU 119(同余)

题目大意:如果A0*X + B0*Y能够整除 N,求出来多有少A*X+B*Y 也能够整除去N,求出所有的A,B(0<=A,B<N) 分析:有条件可以知道 A*X+B*Y = K *(A0*X + B0*Y)% N ====> (K * A0) % N = A, (K * B0) % N = B, (k=[0....N)). ps.记得排序去重复...... 代码如下: ============================================================

SGU 438 The Glorious Karlutka River =) 拆点+动态流+最大流

The Glorious Karlutka River =) Time Limit:500MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice SGU 438 Appoint description: Description A group of Mtourists are walking along the Karlutka river. They want to cross

sgu Kalevich Strikes Back

这道题就是求一个大矩形被n个矩形划分成n+1个部分的面积,这些矩形之间不会相交,可能包含.. 1 #include <cstdio> 2 #include <cstring> 3 #include <vector> 4 #include <algorithm> 5 #define maxn 120100 6 using namespace std; 7 8 long long s[maxn]; 9 vector<int>g[maxn]; 10 i

数学计数原理(P&#243;lya,高精度):SGU 294 He&#39;s Circles

He's Circles He wrote n letters "X" and "E" in a circle. He thought that there were 2n possibilities to do it, because each letter may be either "X" or "E". But Qc noticed that some different sequences of letters ca

sgu Ice-cream Tycoon

题意:供应商提供n块价格为c的冰淇淋,一个学生想买n块冰淇淋,手中的钱数总共有t元,为了不让买n块冰淇淋所花费的钱数不超过t元,先尽可能卖给这个学生便宜的冰淇淋. 如果这个学生不能买到所需要的冰淇淋则输出“UNHAPPY”,能则输出“HAPPY”. 1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 #define maxn 200000 5 using namespace std; 6 7

sgu 463 - Walking around Berhattan

K - Walking around Berhattan Time Limit:250MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Practice SGU 463 Description As you probably know, Berhattan is a district of Berland's largest city and it consists of equal squar

nyoj 119 士兵杀敌(三) 【线段树】【单点更新】

题意:... 策略如题. 思路:我们先假设只求某一区间的最大值,我们只需要利用线段树的模板,只需要初始化和询问的时候小小的修改一下,改成祖先结点储存的不再是子节点的和而是两个子节点之间的最大值,这样我们可以求出最大值了,最小值也是这样求. 注意:因为询问的时候既要求最大值又要求最小值,所以要返回结构体. 代码: #include <stdio.h> #include <string.h> #define M 100005 struct node{ int left, right;

【SGU 390】Tickets (数位DP)

Tickets Description Conductor is quite a boring profession, as all you have to do is just to sell tickets to the passengers. So no wonder that once upon a time in a faraway galaxy one conductor decided to diversify this occupation. Now this conductor