腾讯软开第三题ac代码

#include<iostream>
#include<vector>
#include<unordered_map>

using namespace std;

bool solution(int A,int B,int C)
{
    int t=A%B,res=t;
    int n=1;
    unordered_map<int,int> M;
    while(!M[res])
    {
        if(res==C)
            return true;
        M[res]=1;
        n;
        res=(n*t)%B;
    }
    return false;
}

int main()
{
    int t;
    cin>>t;
    vector<string> Ans(t,"");
    for(int i=0;i<t; i)
    {
        int A,B,C;
        cin>>A>>B>>C;
        if(B==1&&C!=0)
            Ans[i]="NO";
        else
        {
            if(C==0)
                Ans[i]="YES";
            else
            {
               if(solution(A,B,C))
                   Ans[i]="YES";
                else Ans[i]="NO";
            }
        }
    }
    
    for(auto& s:Ans)
        cout<<s<<endl;
}


前两题不会嗯,神仙们打架去吧
#算法工程师#
全部评论
对 第三题很良心了
点赞 回复 分享
发布于 2018-09-16 12:06
做前两题没心情了,结果最后一题,哎
点赞 回复 分享
发布于 2018-09-16 12:12
https://www.nowcoder.com/discuss/110626
点赞 回复 分享
发布于 2018-09-16 12:15
import java.util.Scanner; public class dsadqwdq {        public static void main(String[] args) throws Exception {            Scanner sc = new Scanner(System.in);       int MLCM =0;       int MNLCM =0;       int n=0;       n=sc.nextInt();       int m=n+1;       int i=0;       while(true) {             MLCM=m;             MNLCM=m;                     while(true) {                           int num=0;                for( i=n+1;i<=m;i++) {                    num+=MNLCM%i;                }                                if(num==0) {                    break;                }                else {                    MNLCM=MNLCM+1;                }                            }                                    while(true) {                int num=0;                for( i=1;i<=m;i++) {                    num+=MLCM%i;                }                                if(num==0) {                    break;                }                else {                    MLCM=MLCM+1;                }                       }                       if(MLCM == MNLCM) {               break;           }else {               m=m+1;           }       }       System.out.println(m);        } } 第一题 瞎JB写的
点赞 回复 分享
发布于 2018-09-16 12:17

相关推荐

牛仔知道哦:你是我见过最美的牛客女孩
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务