zoukankan      html  css  js  c++  java
  • Lightoj 1014

    I have an Ifter party at the 5th day of Ramadan for the contestants. For this reason I have invited C contestants and arranged P piaju's (some kind of food, specially made for Ifter). Each contestant ate Q piaju's and L piaju's were left (L < Q).

    Now you have to find the number of piaju's each contestant ate.

    Input

    Input starts with an integer T (≤ 325), denoting the number of test cases.

    Each case contains two non-negative integers P and L (0 ≤ L < P < 231).

    Output

    For each case, print the case number and the number of possible integers in ascending order. If no such integer is found print 'impossible'.

    简化问题,求一个数的所有因子。.....sqrt(n)

    /* ***********************************************
    Author        :guanjun
    Created Time  :2016/6/18 22:38:57
    File Name     :1014.cpp
    ************************************************ */
    #include <iostream>
    #include <cstring>
    #include <cstdlib>
    #include <stdio.h>
    #include <algorithm>
    #include <vector>
    #include <queue>
    #include <set>
    #include <map>
    #include <string>
    #include <math.h>
    #include <stdlib.h>
    #include <iomanip>
    #include <list>
    #include <deque>
    #include <stack>
    #define ull unsigned long long
    #define ll long long
    #define mod 90001
    #define INF 0x3f3f3f3f
    #define maxn 10010
    #define cle(a) memset(a,0,sizeof(a))
    const ull inf = 1LL << 61;
    const double eps=1e-5;
    using namespace std;
    priority_queue<int,vector<int>,greater<int> >pq;
    struct Node{
        int x,y;
    };
    struct cmp{
        bool operator()(Node a,Node b){
            if(a.x==b.x) return a.y> b.y;
            return a.x>b.x;
        }
    };
    
    bool cmp(int a,int b){
        return a>b;
    }
    vector<ll>v;
    int main()
    {
        #ifndef ONLINE_JUDGE
        freopen("in.txt","r",stdin);
        #endif
        //freopen("out.txt","w",stdout);
        int T;
        ll p,l;
        cin>>T;
        for(int t=1;t<=T;t++){
            printf("Case %d: ",t);
            v.clear();
            scanf("%lld %lld",&p,&l);
            ll n=p-l;
            for(ll i=1;i*i<=n;i++){
                if(n%i==0){
                    if(i>l)v.push_back(i);
                    if(n/i>l&&(i*i!=n))v.push_back(n/i);
                }
            }
            sort(v.begin(),v.end());
            int m=v.size();
            for(int i=0;i<m;i++){
                printf("%lld%c",v[i],i==m-1?10:' ');
            }
            if(m==0)puts("impossible");
        }
        return 0;
    }
  • 相关阅读:
    学习C#的一些笔记
    SQL高级应用
    SQL SERVER 视图
    ES5 Study
    面试官技巧
    WebServicexml操作
    用JS和HTML写自己的文本编辑器
    解决Win7 x64 VS2010调试网站出现 vs2010 未能将脚本调试器附加到计算机上的进程。已附加了一个调试器
    Microsoft.Practices.Unity实现代码依赖注入、XML依赖注入和AOP切面编程
    无法对数据库'XXX' 执行删除,因为它正用于复制"的解决方法
  • 原文地址:https://www.cnblogs.com/pk28/p/5597120.html
Copyright © 2011-2022 走看看