ZOJ2674 Strange Limit

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/liutian429073576/article/details/53575205

欧拉函数….

#include<cstdio>
#include<cmath>
#include<iostream>
using namespace std;



int p;

int Fai(int x)
{
    int t=sqrt(x),res=1;
    for(int i=2;i<=t&&i<=x;i++)
    if(x%i==0)
    {
        x/=i;
        res*=i-1;
        while(x%i==0)
            x/=i,res*=i;    
    }
    if(x!=1)res*=x-1;
    return res;
}

int Pow(int a,int x,int M)
{
    int res=1;
    for(;x;x>>=1,a=a*1ll*a%M)
    if(x&1)res=res*1ll*a%M;
    return res;
}

int Solve(int A)
{
    int de=1,d=0;
    while(A%p==0)d++,A/=p,de*=p;
    if(A==1)
        return 0;
    int t=Fai(A),dd,iv=Pow(p,t-1,A);
    dd=Solve(Fai(A));

    return de*((Pow(iv,d,A)*1ll*Pow(p,dd,A))%A);
}


int main()
{
    int m;
    int f=1;
    while(scanf("%d%d",&p,&m)==2)
    {
        if(!f)puts("");
        f=0;
    int t=m;
    while(--m)t*=m;
    int A=Solve(t);
    printf("%d\n",A);
    }
    return 0;
}
阅读更多

Strange Billboard

12-02

Problem DescriptionnThe marketing and public-relations department of the Czech Technical University has designed a new reconfigurable mechanical Flip-Flop Bill-Board (FFBB). The billboard is a regular two-dimensional grid of R ×C square tiles made of plastic. Each plastic tile is white on one side and black on the other. The idea of the billboard is that you can create various pictures by flipping individual tiles over. Such billboards will hang above all entrances to the university and will be used to display simple pictures and advertise upcoming academic events. nnTo change pictures, each billboard is equipped with a ”reconfiguration device”. The device is just an ordinary long wooden stick that is used to tap the tiles. if you tap a tile, it flips over to the other side, i.e., it changes from white to black or vice versa. Do you agree this idea is very clever? nnUnfortunately, the billboard makers did not realize one thing. The tiles are very close to each other and their sides touch. Whenever a tile is tapped, it takes all neighboring tiles with it and all of them flip over together. Therefore, if you want to change the color of a tile, all neighboring tiles change their color too. Neighboring tiles are those that touch each other with the whole side. All inner tiles have 4 neighbors, which means 5 tiles are flipped over when tapped. Border tiles have less neighbors, of course. nn![](http://acm.hdu.edu.cn/data/images/C106-1001-1.JPG)nnnFor example, if you have the billboard configuration shown in the left picture above and tap the tile marked with the cross, you will get the picture on the right. As you can see, the billboard reconfiguration is not so easy under these conditions. Your task is to find the fastest way to ”clear” the billboard, i.e., to flip all tiles to their white side. n nnInputnThe input consists of several billboard descriptions. Each description begins with a line containing two integer numbers R and C (1 ≤ R, C ≤ 16) specifying the billboard size. Then there are R lines, each containing C characters. The characters can be either an uppercase letter “X” (black) or a dot “.” (white). There is one empty line after each map. nThe input is terminated by two zeros in place of the board size.n nnOutputnFor each billboard, print one line containing the sentence “You have to tap T tiles.”, where T is the minimal possible number of taps needed to make all squares white. if the situation cannot be solved, output the string “Damaged billboard.” instead. n nnSample Inputn5 5nXX.XXnX.X.Xn.XXX.nX.X.XnXX.XXn5 5n.XX.Xn.....n..XXXn..X.Xn..X..nn1 5n...XXnn5 5n...X.n...XXn.XX..n..X..n.....nn8 9n..XXXXX..n.X.....X.nX..X.X..XnX.......XnX.X...X.XnX..XXX..Xn.X.....X.n..XXXXX..nn0 0n nnSample OutputnYou have to tap 5 tiles.nDamaged billboard.nYou have to tap 1 tiles.nYou have to tap 2 tiles.nYou have to tap 25 tiles.

Strange Graph

07-18

DescriptionnnLet us consider an undirected graph G = < V,E >. Let us denote by N(v) the set of vertices connected to vertex v (i.e. the set of neighbours of v). Recall that the number of vertices connected to v is called the degree of this vertex and is denoted by deg v. nWe will call graph G strange if it is connected and for its every vertex v the following conditions are satisfied: n1. deg v >= 2 (i.e. there are at least two vertices connected to v) n2. If deg v = 2 then the two neighbours of v are not connected by an edge n3. If degv > 2 then there is u ∈ N(v), such that the following is true: n(a) deg u = 2 n(b) Any two different vertices w1,w2 ∈ N(v) \ u are connected, i.e. (w1,w2) ∈ E.nnYou are given some strange graph G. Find hamiltonian cycle in it, i.e. find such cycle that it goes through every vertex of G exactly once.nInputnnThe first line of the input file contains two integer numbers N and M -- the number of vertices and edges in G respectively (3 <= N <= 10 000, M <= 100 000). 2M integer numbers follow -- each pair represents vertices connected by the corresponding edge (vertices are numbered from 1 to N). It is guaranteed that each edge occurs exactly once in the input file and that there are no loops (i.e. ends of each edge are distinct).nOutputnnIf there is no hamiltonian cycle in G, print -1 on the first line of the output file. In the other case output N numbers -- the sequence of vertices of G as they appear in the hamiltonian cycle found (note that the last vertex must be connected to the first one). If there are several solutions, output any one.nSample Inputnn4 4n1 2 2 3 3 4 4 1nSample Outputnn1 2 3 4

what a strange question!!!!!

01-15

private void Page_Load(object sender, System.EventArgs e)rn rn // 在此处放置用户代码以初始化页面rn rn Table table1=new Table();rn rn TableRow row=new TableRow() ;rn rn for(int j=0;j<2;j++)rn rn TableCell cell = new TableCell();rn if(j==0)rn rn CheckBox checkbox=new CheckBox();rn checkbox.ID="aaa";//这里改成checkbox.ID=j.ToString()点击按钮就不到,只能给定具体ID才能找到rn rn cell.Controls.Add(checkbox);rn rn rn row.Cells.Add(cell);rn table1.Rows.Add(row);rn rn rn rn table1.Style.Add("position","absolute");rn table1.Style.Add("left","200px");rn table1.Style.Add("top","200px");rn table1.Style.Add("width","100");rn table1.Style.Add("height","100");rn table1.BorderWidth=1;rn Page.FindControl("Form1").Controls.Add(table1);rn rn rnrn #region Web 窗体设计器生成的代码rn override protected void OnInit(EventArgs e)rn rn //rn // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。rn //rn InitializeComponent();rn base.OnInit(e);rn rn rn /// rn /// 设计器支持所需的方法 - 不要使用代码编辑器修改rn /// 此方法的内容。rn /// rn private void InitializeComponent()rn rn this.Button1.Click += new System.EventHandler(this.Button1_Click);rn this.Load += new System.EventHandler(this.Page_Load);rnrn rn #endregionrnrn private void Button1_Click(object sender, System.EventArgs e)rn rn CheckBox checkbox1=new CheckBox();rn for(int i=0;i<2;i++)rn checkbox1=(CheckBox)Page.FindControl("aaa");//这里把"aaa"改成i.ToString()就找补到该空间WHY???rn if(checkbox1!=null&&checkbox1.Checked==true)rn Response.Write(" ");rn rn

没有更多推荐了,返回首页